On Monday, 31 March 2014 13:03:57 UTC-4, Christian Gruber wrote:
>
> This actually looks a lot like a ListMultimapBinder to me. :) 
>

I don't see why, what type would the key have and where would they come 
from?
 

> Regardless, I think it's potentially a cool idea, though I'm not sure 
> it's vastly superior (for dealing with edge-cases) than. 
>
> Multibinder mb = Multibinder.create(binder(), Foo.class); 
> ... 
> //elsehwere 
>
> @Provides SortedSet<Foo> sortedListOfFoo(Set<Foo> foos) { 
>    ImmutableSortedSet.copyOf(MY_SORT_COMPARATOR, food); 
> } 
>
> except for maybe visibility or edge-case performance considerations, or 
> where you need to somehow hide the visibility of Set<Foo>.  Maybe the 
> visibility concern is enough reason to support this... but I wonder 
> about the behavior of overloaded priorities. :/ 
>

The main difference is that the ordering decisions can be split across 
modules.  This is only a partial decoupling though, because if something is 
required to come before/after the Foos from another module then you still 
need to know what priorities that module uses.  So it's not great if you 
have lots of objects, but if you only have a few spread over a few modules 
it should be maintainable.  A slight improvement is something like this:

ListBinder<Snack> listBinder = ListBinder.createWithPriority(100, binder(), 
Snack.class);
listBinder.addBinding().toInstance(new Twix());
listBinder.addBinding().toProvider(SnickersProvider.class);
listBinder.addBinding().to(Skittles.class);

where the priority only matters for inter-module ordering.

I think a simple list is impossible without having to have implicit 
> strategies for resolving those priorities - a ListMultimapBinder could 
> work though.
>

A ListMultimapBinder would have the same issues potentially:

// Some module
listMultimapBinder.addBinding("foo").toInstance("bar");

// Another module
listMultimapBinder.addBinding("foo").toInstance("baz");

Now what's the ordering in the List<String> returned by 
listMultimap.get("foo")?

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

Reply via email to