Compile time dependency injection with filters?

185 views
Skip to first unread message

Yevgeniy Brikman

unread,
Jun 29, 2015, 3:53:21 AM6/29/15
to play-fr...@googlegroups.com
Is there any way to use the Scala Compile Time Dependency Injection with Filters? For example, I have a Filter class that needs a Cache class injected. I'm using compile time injection, so I can't just use an @Inject annotation. However, it seems that Play loads the Filters via reflection from one configuration parameter (play.http.filters) and the rest of the application through a different configuration parameter (play.application.loader) and I can't find a way to make the two worlds play together nicely.

Thanks,
Jim 

Yevgeniy Brikman

unread,
Jun 29, 2015, 5:16:08 AM6/29/15
to play-fr...@googlegroups.com
Answering my own question: it turns out that the BuiltInComponentsFromContext include a variable called httpFilters that you can override to provide your own filters. Example:

class MyLoader extends ApplicationLoader {
  override def load(context: Context): Application = {
    new MyComponents(context).application
  }
}

class MyComponents(context: Context) extends BuiltInComponentsFromContext(context) {
  val myFilter = new CustomFilter()
  override lazy val httpFilters = Seq(myFilter)
}

Jim

Marius Soutier

unread,
Jun 29, 2015, 8:47:54 AM6/29/15
to play-fr...@googlegroups.com
Just had the exact same question - would be cool to add this to the documentation.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/9af49529-441b-4b6e-ad0d-319f59dd0384%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michal Gabrysiak

unread,
Nov 18, 2015, 8:43:56 AM11/18/15
to play-framework
Hi Yevgeniy Brikman,

Did you find possibility to connect
play.application.loader with play.http.filters in one project?

Reply all
Reply to author
Forward
0 new messages