Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add support for injecting into Map<String,T> (by qualifier) #230

Closed
rbygrave opened this issue Jun 8, 2022 · 0 comments · Fixed by #231
Closed

ENH: Add support for injecting into Map<String,T> (by qualifier) #230

rbygrave opened this issue Jun 8, 2022 · 0 comments · Fixed by #231
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@rbygrave
Copy link
Contributor

rbygrave commented Jun 8, 2022

Inject map of beans keyed by qualifier name.

@Singleton
public class CombinedMapSomei {

  private final Map<String, Somei> somes;

  /**
   * Inject map of beans keyed by qualifier name.
   */
  @Inject
  public CombinedMapSomei(Map<String, Somei> somes) {
    this.somes = somes;
  }

Get dependencies as a map keyed by qualifier name

      SomeStore greenStore = beanScope.get(SomeStore.class, "green");
      SomeStore blueStore = beanScope.get(SomeStore.class, "blue");

      // get dependencies as a map keyed by qualifier name
      Map<String, SomeStore> stores = beanScope.map(SomeStore.class);

      SomeStore green = stores.get("green");
      assertThat(green).isSameAs(greenStore);
      SomeStore blue = stores.get("blue");
      assertThat(blue).isSameAs(blueStore);
@rbygrave rbygrave added the enhancement New feature or request label Jun 8, 2022
@rbygrave rbygrave added this to the 8.6 milestone Jun 8, 2022
@rbygrave rbygrave self-assigned this Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant