xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Multibinder should accept bindings to sets of elements #662

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Multibinder should accept bindings to sets whose size is not known until 
injector creation and then add all the elements of the sets to the multibound 
set.  Contrived example:

Multibinder.newSetBinder(binder(), User.class, MyAnnotation.class)
  .addSetBinding().toProvider(HappyEngineersProvider.class);

class HappyEngineersProvider implements Provider<Set<User>> {
  @Inject Company company;

  @Override public Set<User> get() {
    Set<User> happyEngineers = new HashSet<User>();
    for (User e : company.getEngineers())
      if (e.isHappy())
        happyEngineers.add(e);
    return happyEngineers;
  }
}

Original issue reported on code.google.com by mattmccu...@google.com on 21 Oct 2011 at 9:12