8000 Multibindings limitations (Lazy values, Multiple keys for a value) · Issue #3908 · google/dagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Multibindings limitations (Lazy values, Multiple keys for a value) #3908
Open
@maksym-moroz

Description

@maksym-moroz

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

  1. 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 for Map<Key, <Provider<Value>> while scoping the provisions themselves with a Singleton 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.
  2. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0