5

I know this may not be dependency injection in its purest form, but let's say I have to use :

@Inject
Injector injector;

With this injector, is it possible to get all the binded instances given :

  1. A parent class each instances would inherited from?
  2. An interface each instances would implement?
  3. An annotation each instances would have?

I see the Injector#findBindingsByType() method but I'm not sure if it can help in that regard.

Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
electrotype
  • 8,342
  • 11
  • 59
  • 96

1 Answers1

1

You can inject a list of a given type associated through multibindings. Check out the docs:

https://github.com/google/guice/wiki/Multibindings

Esko
  • 29,022
  • 11
  • 55
  • 82
John Ericksen
  • 10,995
  • 4
  • 45
  • 75
  • http://stackoverflow.com/questions/6085200/how-to-get-all-implementors-subclasses-of-an-interface-with-guice/40558788#40558788 describes a way to "auto-discover" instances by implemented interface as a more dynamic alternative to explicit multi bindings. – vorburger Nov 12 '16 at 01:58