Created
September 19, 2012 13:10
-
-
Save mathieuancelin/3749569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import play.*; | |
import play.mvc.*; | |
import views.html.*; | |
import services.*; | |
import javax.enterprise.context.*; | |
import javax.inject.*; | |
@ApplicationScoped | |
public class Application extends Controller { | |
@Inject HelloService helloService; | |
public Result index() { | |
return ok(index.render(helloService.hello())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import Keys._ | |
import PlayProject._ | |
object ApplicationBuild extends Build { | |
val appName = "play2-cdi" | |
val appVersion = "1.0-SNAPSHOT" | |
val appDependencies = Seq( | |
// Add your project dependencies here, | |
"org.jboss.weld.se" % "weld-se" % "1.1.9.Final" | |
) | |
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings( | |
// Add your own project settings here | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.*; | |
import org.jboss.weld.environment.se.ShutdownManager; | |
import org.jboss.weld.environment.se.Weld; | |
import org.jboss.weld.environment.se.WeldContainer; | |
public class Global extends GlobalSettings { | |
private WeldContainer weld; | |
@Override | |
public void onStart(Application app) { | |
weld = new Weld().initialize(); | |
} | |
@Override | |
public void onStop(Application app) { | |
shutdown(weld); | |
} | |
@Override | |
public <A> A getControllerInstance(Class<A> clazz) { | |
return weld.instance().select(clazz).get(); | |
} | |
private void shutdown(WeldContainer weld) { | |
ShutdownManager shutdownManager = weld.instance().select(ShutdownManager.class).get(); | |
shutdownManager.shutdown(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package services; | |
import javax.enterprise.context.*; | |
@ApplicationScoped | |
public class HelloService { | |
public String hello() { | |
return "Hello world!"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET / @controllers.Application.index() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /scala @controllers.ScalaController.index() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import play.api._ | |
import play.api.mvc._ | |
import javax.inject._ | |
import javax.enterprise.context._ | |
import services._ | |
class ScalaController extends Controller { | |
@Inject var helloService: HelloService = _ | |
def index() = Action { implicit request => | |
Ok( views.html.index( helloService.hello( ) ) ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment