Reputation: 9209
How to define a controller class in playframework (that will be injected by a dependency container)?
For the app/controllers/controller
package controllers
import play.api.Play
/*object*class MainController(name:String) {
import play.api.Play.current
def index = Ok(Html("index ok "+name))
}
My app/Global.scala
package app
object Global extends GlobalSettings with SecuredSettings with Logger {
override def getControllerInstance[A](controllerClass: Class[A]) =
new MainController("first")
}
My conf/routes
file is
GET / controllers.MainController.index
I get the following error
[error] ............/conf/routes:1: value index is not a member of object controllers.MainController
[error] GET / controllers.MainController.index
Upvotes: 0
Views: 1149
Reputation: 44
I suggest looking up the official documentation. Which also contains links to repositories with examples of how to get started with the dependency injection framework of choice.
https://www.playframework.com/documentation/2.3.x/ScalaDependencyInjection
Might be worth keeping in mind that play 2.4.x will use Guice by default.
Upvotes: 1