Guice: Is it possible to get all instances with binding for a specific parent / interface / annotation?

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

@Inject Injector injector; 

Using this injector, you can get all related instances:

  • A parent class that each instance would inherit from?
  • The interface that each instance will implement?
  • Annotations that each instance would have?

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

+4
source share
1 answer

You can enter a list of a given type, linked using multi-exchange. Check documents:

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

+1
source

Source: https://habr.com/ru/post/1436682/


All Articles