Take the 2-minute tour ×

We have a new Play 2.0 project and we are planning to introduce DI as we add some complex 3rd party integration code.

There is a Guice plugin for Play 2.0 but it looks like it will be obsolete at 2.1 and I have a hunch that 2.1 is not that far anymore.


Is Guice a safe bet for Play 2.0/2.1 or should we consider other options?

share|improve this question
What is play plugin ? –  Bhavik Ambani Nov 13 '12 at 9:22

1 Answer 1

up vote 8 down vote accepted

I'd go with the 2.1 version, and the new controller instanciation from the Global object.

Here is a Guice example from the doc:

  import play.GlobalSettings;

  import com.google.inject.Guice;
  import com.google.inject.Injector;

  public class Global extends GlobalSettings {

    private static final Injector INJECTOR = createInjector(); 

    public <A> A getControllerInstance(Class<A> controllerClass) throws Exception {
      return INJECTOR.getInstance(controllerClass);

    private static Injector createInjector() {
      return Guice.createInjector();


You have to declare a special route for these controllers, with the special @:

GET    /myUrl       @controllers.MyController.myMethod()

And you can also take a look at this demo using Spring: https://github.com/guillaumebort/play20-spring-demo

share|improve this answer

Your Answer


