Open maksym-moroz opened 1 year ago
For #1 that feature request is filed here (https://github.com/google/dagger/issues/1630).
For #2 there's no existing feature request, but there's a few ways you can work around it by adding a bit of extra setup. For example, one option is to bind the same implementation to multiple keys:
@Module
interface MyModule {
@Binds
@IntoMap
@RouteKey("one")
Value bindImplOne(ValueImpl impl);
@Binds
@IntoMap
@RouteKey("two")
Value bindImplTwo(ValueImpl impl);
@Binds
@IntoMap
@RouteKey("three")
Value bindImplThree(ValueImpl impl);
// Possibly scope this if you need the map to return the same instance for each key
static class ValueImpl extends Value {
@Inject
ValueImpl(...) {...}
}
}
Thanks for a quick response. This is more or the less the way I implemented it so far, just wanted to create this issue
I am trying to utilize Dagger multibinding capabilities to abstract away some menial work. I have a multi module Gradle project and I am using
@IntoMap
multibindings in feature modules to then use the whole map in the app module without passing and wiring everything directly.Right now I am facing two issues
Map<Key, Lazy<Value>>
and I wasn't able to find anything concrete on this topic. As a temporary solution, I am able to achieve the desired effect by asking forMap<Key, <Provider<Value>>
while scoping the provisions themselves with aSingleton
scope but I would like to the see the direct support for Lazy multibindings or the reason why there is no out-of-the-box support for ones.This is what I imagine it could look like
Where
@RouteKey
is aMapKey
annotated with@Repeatable
. I think allowing default@StringKey
to be repeatable would be ideal while teaching Dagger to support several keys/aliases for custom map keys via repeatable annotation would be a good start.