In the previous example, we have developed our first Play Framework HelloWorld Web Application.
For a clear separation between the Play Web Application with DI and without DI, I'll create a new project with the same content without changing the previous project:
- Create a Play Framework SBT Project from your favorite IDE (I am using IntelliJ IDEA):
Project Name: play-scala-helloworld-di-app
- Copy the complete content of play-scala-helloworld-app into this project.
- Create a HelloWorld Play Controller with DI:
HelloWorldDIController.scala:
package controllers import javax.inject._ import play.api.mvc._ @Singleton class HelloWorldDIController @Inject() extends Controller { def helloWorld = Action { Ok(views.html.helloWorld("Hello World With DI.")) } }
We will use the same Play View Template for both HelloWorld Controllers...