User Router in Playframework 2.4

I am using Play 2.4. I would like to replace the default router with my own class, using the new dynamic injection dependency feature. What are the steps for this?

+7
scala url-routing playframework
source share
1 answer

One possible solution would be to create a new Guice Module to bind a new router:

class RouterModule extends AbstractModule { override def configure(): Unit = { bind(classOf[Router]).to(classOf[CustomRouter]) } } 

Next, define a new Application Loader that will override the default router using the newly created module:

 class MyApplicationLoader extends GuiceApplicationLoader with GuiceableModuleConversions { override protected def overrides(context: Context): Seq[GuiceableModule] = { Seq(fromGuiceModule(new RouterModule)) ++ super.overrides(context) } } 

And use the newly created application loader, not the default, in application.conf:

 play.application.loader = "de.zalando.store.pdp.modules.MyApplicationLoader" 
+3
source share

All Articles