I have an ActionBuilder
LoggingAction that executes in every request:
object LoggingAction extends ActionBuilder[Request]{
def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {
Logger.info("Logging some things")
block(request)
}
}
Now, I need to access the cache API in the LoggingAction object (the one that extends ActionBuilder
. However, in Play 2.5.x, the cache object is obtained through injection only in the class that extends Controller
:
class ProcessLogin @Inject() (cache: CacheApi) extends Controller {
//...
}
I need to access the cache API in the ActionBuilder
object, but I cannot inject it because it doesn't extend Controller
. Is there a way to achieve this?
UPDATE
One option could be to inject at field level, but it doesn't work as the field remains null
when the cache API is used:
@Inject val cache: CacheApi = null