- If using,
play 2.0.2, add
"com.typesafe" % "play-plugins-guice" % "2.0.3"
to your build.scala file. For play 2.0.1, add"com.typesafe" % "play-plugins-guice" % "2.0.2"
to your build.scala file. - Create a file called
play.plugins
in yourapp/conf
directory - Add
1500:com.typesafe.plugin.inject.GuicePlugin
- Re-run eclipsify command from the play prompt. Initially, I didn't know that I have to do this, and I was struggling for several hours.
- Then define Dependency class in module package and inject the service. That's it
Dependencies.java
package module;
import com.google.inject.*;
import service.*;
public class Dependencies implements Module {
public void configure(Binder binder) {
binder.bind(Service.class).to(SomethingService.class);
}
}
Application.java
import javax.inject.*;
import service.*;
public class Application extends Controller {
@Inject static Service s;
public static Result index() {
return ok(index.render(s.demonstrate()));
}
return ok(index.render(s.demonstrate()));
}
}
No comments:
Post a Comment