Closed GoogleCodeExporter closed 8 years ago
Hi,
This looks like somewhere in your code, you try to inject an HandlerManager
directly,
instead of injecting your EventBus.
For example, if you have a constructor somewhere like:
@Inject
public MyConstructor(HandlerManager manager, ...)
Gin will try to inject the HandlerManager class directly, which is not possible
since
HandlerManager has no constructor defined with @Inject
If this is the case, there are two solutions:
a)Find all fields/methods/constructors injected with HandlerManager, and
replace it
with EventBus
b) Bind HandlerManager to EventBus in your module:
bind(HandlerManager.class).to(EventBus.class).in(Singleton.class);
That way, when Gin needs to inject an HandlerManager, it will use the EventBus
subclass, which is indeed injectable...
Note: with the second solution, you might have scoping problems... Maybe you
will end
up with 2 singletons (the first one for the HandlerManager binding, the second
one
for the EventBus binding...).
Best regards,
-Etienne
Original comment by nev...@gmail.com
on 8 Nov 2009 at 11:50
Etienne,
Issue solved. Thank you for pointing out what probably seemed obvious. I was
racking
my brain but the issue was exactly as you described. I was injecting
HandlerManager
directly, and I was specifying
public HandlerManager getEventBus();
in my Ginjector.
After I changed everything to EventBus it worked like a charm.
All the best,
-Tristan
Original comment by Tristan....@gmail.com
on 8 Nov 2009 at 4:15
I think your bindings should have included the HandlerManager, after all,
that's what
Guice/Gin is about: :)
bind(HandlerManager.class).to(EventBus.class).in(Singleton.class);
Original comment by aragos
on 9 Nov 2009 at 10:32
@Tristan:
No problems, I'm glad I could help :) We all make mistakes!
@Aragos:
Even better, I think the "EventBus" should be an interface (not a subclass of
HandlerManager), with a "DefaultEventBus" that extends HandlerManager and
implements
this EventBus interface.
Then
bind(EventBus.class).to(DefaultEventBus.class).in(Singleton.class);
Then, in the code, inject the EventBus interface everywhere. That way you
abstract
out all implementation details, and you may switch out the HandlerManager
"implementation" for another one if needed... And you may now mock your
EventBus more
easily in your tests :)
Original comment by nev...@gmail.com
on 10 Nov 2009 at 10:55
Original issue reported on code.google.com by
Tristan....@gmail.com
on 8 Nov 2009 at 2:44