Guice : Is it possible to get all binded instances given a particular parent/interface/annotation?
-
04-07-2021 - |
Question
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 :
- A parent class each instances would inherited from?
- An interface each instances would implement?
- An annotation each instances would have?
I see the Injector#findBindingsByType() method but I'm not sure if it can help in that regard.
Solution
You can inject a list of a given type associated through multibindings. Check out the docs:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow