Scala: Implementing Java's AspectJ around advice or Python decorators

I have been using Java + AspectJ extensively for my startup. I would love to switch to Scala but I have a common design pattern that I am not sure entirely the best way to implement in Scala.

A tremendous amount of our application uses AspectJ pointcuts using annotations as the marker. This is very similar to Python's decorator and blogged about it here.

I have tried doing this technique in Scala but had problems with AspectJ + Scala. Even if I did get it to work it seems unScala like.

I have seen some projects do some call-by-name closure magic (I think thats what they are doing).

Example of a replace of @Transaction:

transaction {
// code in here.
}

I have to say though I prefer the annotation more as it seems more declarative. What is the Scala way of declaratively "decorating" code blocks?

7
задан Community 23 May 2017 в 12:23
поделиться