PsychoX
PsychoX

Reputation: 1098

How to add module to Play! Framework 2.4

I'm trying to separate some application logic into modules. I've created module which is supposed to handle users (view profile etc. (models + controllers))

I've added module into reference.conf

play.modules.enabled += "modules.users"

But when I try to access app:

Module [modules.users] cannot be instantiated.

Is creating Custom loader only option?

Upvotes: 2

Views: 4911

Answers (1)

Julien Lafont
Julien Lafont

Reputation: 7877

This syntax works only with runtime dependency injection: the configuration is read at runtime, and the required modules are loaded.

The module "name" must reference a Guice Module, where you define your custom bindings.

One full example:

conf/application.conf

play.modules.enabled += "auth.di.AuthModule"

modules/auth/app/di/AuthModule.scala

package auth.di

class AuthModule extends AbstractModule {

   def configure() = {
       // Binds your services here
   }
}

build.sbt

lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .dependsOn(moduleAuth).aggregate(moduleAuth)

lazy val moduleAuth = (project in file("modules/auth"))
   .enablePlugins(PlayScala)

Tips: Use scala-guice to define your modules more fluently.

Upvotes: 2

Related Questions