Imagine you have a PlayN game which uses Guice bindings in its core project:
/* PlayN core Guice module */
public class MyGameModule extends AbstractModule {
@Override
protected void configure() {
bindConstant().annotatedWith(Title.class).to("My game title");
// Other bindings...
}
}
What if you want to use those same bindings, but on your GWT project of the game (with Gin)?
In the Java project it's as easy as it gets:
/* PlayN Java Guice module */
public class MyGameModuleJava extends MyGameModule {
// **OK**: no manual intervention required.
}
Can this be achieved without having to manually copy-paste the Guice module's configure method to the Gin module? For example, this works as a workaround, but is not what I'd prefer to do:
/* PlayN GWT Gin module */
public class MyGameModuleHtml extends AbstractGinModule {
@Override
protected void configure() {
// **NOK**: copy-paste the Guice module, as shown below.
bindConstant().annotatedWith(Title.class).to("My game title");
// Other bindings...
}
}
It works, but it's not pretty to say the least.
Bottom line: I want to use same bindings across all PlayN projects.
Solution
So what I did is use the GinModuleAdapter
in my Java main, based on the answer:
Injector injector = Guice.createInjector(new GinModuleAdapter(new MyGameModuleHtml()));
This way I could remove the Guice bindings in the core classes as well.