Skip to content
Branch: master
Go to file

Latest commit


Failed to load latest commit information.
Latest commit message
Commit time


Bitdeli Badge

Inspired by Guice's excellent ServletModule integration, play2-guice-module takes advantage of some of the new Play 2.1 RC1 features to provide several utility classes to integrate Google Guice into Play.


  • Play 2.1-RC1
  • Java Play project

Getting Started

Play 2.1-RC1 provides hooks to create a "dynamic" controller class with each request. In conf/routes simply prefix each controller action with an @.

# Tell Play to create a new controller with each request by prefixing the action with an `@`:
GET     /                           @controllers.Application.index()

Create a Global object which extends GuiceGlobalSettings as illustrated below...

public class Global extends GuiceGlobalSettings {
    protected Injector createInjector() {
        return Guice.createInjector(Stage.PRODUCTION, new PlayModule() {

            protected void configurePlay() {
                // bind some stuff!

Finally, just annotate your controller method with @With(RequestScopedAction.class) to enable @RequestScoped resources.

public class Application extends Controller {

    // ahhh immutable...
    private final FooPresenter _fooPresenter;

    // yeah, constructor injector!
    Application(FooPresenter fooPresenter) {
        _fooPresenter = fooPresenter;

    // Enable RequestScoped resources for this action
    public Result index() {
        String bar = _fooPresenter.getBar();
        return ok(index.render("Request: " + bar));

Available Injections

Installing the PlayModule automatically gives you access to several classes from the Play framework. These classes are injectable in any Guice injected object by default, when you install the PlayModule...

public class FooPresenter {

    FooPresenter(Http.Request request, Http.Response response, Http.Context context) {


See the sample-app for more details.


  • Support Session Scopes
  • Unit tests :)

Known Issues

Play 2.1-RC1 has a few bugs with publish-local, which make it difficult to use this module:

As a work around, I disabled publishing the main API jar...

publishArtifact in(Compile, packageDoc) := false


play2-guice-module is distributed under the Apache 2 licence.


Google Guice module for Play 2.1



You can’t perform that action at this time.