Search code examples
javagwtguicegwt-gin

Using @Singleton in two Ginjector instances


I have circural dependency problems in a GWT project set ("Main project", "Widgets project", "Service adapter project"). Main references widgets and service adapters. Widgets reference service adapters. And here comes the problem. I would like to use an EventBus practically everywhere, injected. Where should I put my Ginjector interface?

It has to be usable from every project and has to reference classes from every project too, to be able to inject classes from different projects. This is obviously uncompilable.

I thought of using a separate Ginjector for widgets and one for only the EventBus. If two separate Ginjectors use two separate GinModules both containing @Singleton EventBus bindings, the two getters will return the same EventBus instances or not?

Note: It's a Gin, not a Guice question.


Solution

  • The most simple way I can think of is to create EventBus as singleton in separate injector (or make it static final field in some class), then use @Provides in other injectors to gain access to that specific EventBus instance.