Open
Description
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
- I would like to postpone the costly initialization of my components to a later (less critical) point in time, and since those components' initializations are costly I would like for them to stick around so on the next invocation I get the same ones. Right now, Dagger doesn't provide support for
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. - In my business logic the same component can have several aliases and thus might require multiple keys. As of now I wasn't able to make Dagger do this. It's possible to provide them by hand, essentially just writing the same provision with different keys so it should be possible for Dagger to support this use case out-of-the-box as well.
This is what I imagine it could look like
@Provides
@IntoMap
@RouteKey("one")
@RouteKey("two")
@RouteKey("three")
Where @RouteKey
is a MapKey
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.
Metadata
Metadata
Assignees
Labels
No labels