Extend HelloWorld Example With DI
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-appinto 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."))
}
} Note
We will use the same Play View Template for both HelloWorld Controllers.
The following table describes the most important and frequently used Play Web Application annotations:
Annotation | Description |
|