2
votes

I have a module in my Play 2.6.11 app which I want to enable like

play.modules.enabled  += "my.Module"

This works great if I use the default (Guice) application loader provide by Play. However, I also need my custom application loader like

play.application.loader = MyApplicationLoader

Together, my.Module is not instantiated.

Does anyone has experience using these 2 together? I have a hard time finding relevant documentation about this as well.

The Play module docs don't mention custom application loaders.

1

1 Answers

1
votes

You can do this the following way

Custom loader

import play.api.{Application, ApplicationLoader}

class CustomLoader extends ApplicationLoader {
  def load(context: ApplicationLoader.Context): Application =
    new CustomModule(context).application
}

In application.conf

application.loader = CustomLoader

CustomModule can load all other components.