Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guice : Is it possible to get all binded instances given a particular parent/interface/annotation?

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.

like image 258
electrotype Avatar asked Nov 12 '22 21:11

electrotype


1 Answers

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

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

like image 152
John Ericksen Avatar answered Dec 07 '22 23:12

John Ericksen