Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is an example of Play 2.4 application that uses Scaldi for dependency injection.
This is an example of Play 2.6 application that uses Scaldi for dependency injection.

It can be also found as an activator template here:

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import net.sf.ehcache.CacheManager
import play.api.mvc._
import scaldi.{Injectable, Injector}
import service.{ServerStatusService, MessageService}
import play.api.cache.CacheApi
import play.api.cache.AsyncCacheApi

class Application(implicit inj: Injector) extends Controller with Injectable {
val cache = inject [CacheApi]
class Application(implicit inj: Injector) extends InjectedController with Injectable {
val cache = inject [AsyncCacheApi]

val messageService = inject [MessageService]

Expand Down
11 changes: 6 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ name := "scaldi-play-example"

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.7"
scalaVersion := "2.12.4"

libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-cache" % "2.5.0",
"org.scaldi" %% "scaldi-play" % "0.5.14",
"org.specs2" %% "specs2-core" % "3.5" % "test",
"org.specs2" %% "specs2-junit" % "3.5" % "test"
guice,
ehcache,
"org.scaldi" %% "scaldi-play" % "0.5.17",
"org.specs2" %% "specs2-core" % "4.2.0" % "test",
"org.specs2" %% "specs2-junit" % "4.2.0" % "test"
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
Expand Down
4 changes: 2 additions & 2 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="Onk7agCh??yfgRf/^8>2K34@meq_2[IsW<xW]tU>xFP:7QaS=@KlYujZyTSt1hpV"
play.http.secret.key="Onk7agCh??yfgRf/^8>2K34@meq_2[IsW<xW]tU>xFP:7QaS=@KlYujZyTSt1hpV"

# The application languages
# ~~~~~
application.langs="en"
play.i18n.langs=["en"]

# Global object class
# ~~~~~
Expand Down
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ~~~~

# Home page
GET / controllers.Application.index
GET / @controllers.Application.index

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.8
sbt.version=1.1.5
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.13")
44 changes: 31 additions & 13 deletions test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
package test

import org.specs2.mutable._
import play.api.cache.EhCacheModule
import play.api.inject.BuiltinModule

import play.api.test._
import play.api.test.Helpers._
import scaldi.play.{ScaldiApplicationBuilder, ControllerInjector}
import scaldi.Module
import scaldi.play.{ControllerInjector, ScaldiApplicationBuilder}
import scaldi.{Injectable, Module}
import service.MessageService
import modules.{ServerModule, UserModule}
import scaldi.play.condition._
import ScaldiApplicationBuilder._
import controllers.AssetsModule
import play.api.{Application, Configuration, Environment, Logger}
import play.api.cache.ehcache.EhCacheModule
import play.api.http.HeaderNames
import play.api.i18n.I18nModule
import play.api.mvc.{AnyContentAsEmpty, CookiesModule}
import play.filters.csrf.CSRFModule
import play.filters.hosts.{AllowedHostsConfig, AllowedHostsModule}

/**
* Add your spec here.
* You can mock out a whole application including requests, plugins etc.
* For more information, consult the wiki.
*/
class ApplicationSpec extends Specification {

class ApplicationSpec extends Specification with Injectable {

private val logger = Logger(this.getClass)

"Application" should {

"send 404 on a bad request" in {
withScaldiApp() {
status(route(FakeRequest(GET, "/boum")).get) must equalTo(NOT_FOUND)
withScaldiInj() { implicit inj =>
val application = inject[Application]
status(route(application, FakeRequest(GET, "/boum")).get) must equalTo(NOT_FOUND)
}
}

Expand All @@ -37,8 +46,14 @@ class ApplicationSpec extends Specification {
"render the index page (with full control over the module composition)" in {
val module = new TestModule :: new ServerModule :: new UserModule :: new ControllerInjector

withScaldiApp(modules = Seq(module, new EhCacheModule, new BuiltinModule), loadModules = (_, _) => Seq.empty) {
val home = route(FakeRequest(GET, "/")).get
withScaldiInj(
modules = Seq(module, new AllowedHostsModule, new CookiesModule, new AssetsModule, new CSRFModule, new I18nModule, new EhCacheModule, new BuiltinModule),
loadModules = (_, _) => Seq.empty
) { implicit inj =>

val application = inject[Application]

val home = route(application, FakeRequest(GET, "/")).get

status(home) must equalTo(OK)
contentType(home) must beSome.which(_ == "text/html")
Expand All @@ -48,8 +63,11 @@ class ApplicationSpec extends Specification {
}

"render the index page (with just override module)" in {
withScaldiApp(modules = Seq(new TestModule)) {
val home = route(FakeRequest(GET, "/")).get
withScaldiInj(modules = Seq(new TestModule)) { implicit inj =>

val application = inject[Application]

val home = route(application, FakeRequest(GET, "/")).get

status(home) must equalTo(OK)
contentType(home) must beSome.which(_ == "text/html")
Expand All @@ -62,7 +80,7 @@ class ApplicationSpec extends Specification {
val application = new ScaldiApplicationBuilder().prependModule(new TestModule).build()

running(application) {
val home = route(FakeRequest(GET, "/")).get
val home = route(application, FakeRequest(GET, "/")).get

status(home) must equalTo(OK)
contentType(home) must beSome.which(_ == "text/html")
Expand Down