Is it possible to get a list of implementations of an interface/class in dagger?
I am looking at something like Ninject's Multi-Injection.
Already documented.
TL;DR:
In your provider
@Provides @IntoSet Foo provideAFoo() { return AFoo(); }
... other module or same module ...
@Provides @IntoSet Foo provideBFoo() { return BFoo(); }
... and somewhere else...
class Bar {
@Inject Set<Foo> allMyFoos;
}
Starting with Dagger2, the dependencies can be mapped (i.e., java.util.Map
).
Looks like the documentation is not complete, but Dagger already provides this.
for example (extracted from dagger's google group), provide the implementations using Provides.Type.SET
@Provides(type=SET) Foo provideAFoo() { return AFoo(); }
... other module or same module ...
@Provides(type=SET) Foo provideBFoo() { return BFoo(); }
... and somewhere else...
class Bar {
@Inject Set<Foo> allMyFoos;
}
REF: post in dagger's google group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With