Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Router in Playframework 2.4

I'm using Play 2.4. I'd like to replace the default router, with my own class, using the new dynamic dependency injection play feature. What are the steps to do that?

like image 596
Danix Avatar asked May 22 '15 07:05

Danix


1 Answers

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

class RouterModule extends AbstractModule {

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

Then define a new Application Loader, which will override the default configured router, by 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, instead of the default one, in application.conf:

play.application.loader = "de.zalando.store.pdp.modules.MyApplicationLoader"
like image 138
Danix Avatar answered Oct 20 '22 10:10

Danix