Raf
Raf

Reputation: 842

How to add module to Play! Framework 2.6 with custom application loader

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.

Upvotes: 3

Views: 1615

Answers (1)

Nagarjuna Pamu
Nagarjuna Pamu

Reputation: 14825

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.

Upvotes: 1

Related Questions