In Play 2.5.X we need to use dependency injection. The following code is an example from play-documentation:
class HomeController @Inject() (configuration: play.api.Configuration) extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
}
If I define some additional helper method getXXX
in HomeController
and need to access it from somewhere else, how can I access this method?
What I am really interested in is how to create instance of HomeController
so that I can use homeControllerInstance.getXXX
.
If I try to create instance like following:
val homeControllerInstance = new HomeController()
I get error:
Compilation error[not enough arguments for constructor HomeController: (configuration: play.api.Configuration)HomeController
I tried to change HomeController
class declaration to:
class HomeController @Inject(configuration: play.api.Configuration) extends Controller
But this gave me error:
classfile annotation arguments have to be supplied as named arguments
Can someone please explain, how can I fix this?