When it comes to injection, if Gin
does not find a bind for a given type, it automatically fallsback to GWT.create()
to create an instance. This is why ClientBundle
/GWT-RPC
/i18n
and the like, simply Just Works, and you do not have to bind them into your own extension of AbstractGinModule
.
Of course when Gin
finds another injection of the same type, it injects another instance. To create and inject a singleton instance simply bind your GWT-RPC
async service interface into @Singleton
scope. Like this:
public class YourModule extends AbstractGinModule {
@Override
protected void configure() {
bind(MyServiceAsync.class).in(Singleton.class);
}
}
Or you can create a Provider<MyServiceAsync>
that always returns a singleton instance, but the previous approach is far simpler.
A singleton async instance injected throughout your application, is generally preferred.