To be honest, I ran into that same limitation myself and concluded the most
straightforward solution was to use the deprecated
FactoryProvider.newFactory() method.  I didn't want to introduce any more
levels of indirection when there was a clear and understandable working
solution.

I'll sit back and watch this thread to see what other folks think as well.

-Fred

On Thu, Jul 22, 2010 at 2:11 PM, Leigh Klotz <[email protected]> wrote:

> I seem to ask questions about these three things fairly regularly, so
> please bear with me if you find it repetitive.
>
> With earlier versions of assistedinject, I could use
> FactoryProvider.newFactory like this:
>
>  mapbinder.addBinding("orange").
>          toProvider(FactoryProvider.newFactory(FruitFactory.class,
> Orange.class));
>  mapbinder.addBinding("banana").
>          toProvider(FactoryProvider.newFactory(FruitFactory.class,
> Banana.class));
>
>   @Inject Map<String, FruitFactory> map;
>   map.get(fruitname).bear(3);
>
> See discussion of this "command" pattern with mapbinder and
> assistedinject here: http://tinyurl.com/22t28y6
>
> With FactoryModuleBuilder, I'm not sure how to obtain the Provider
> object to put into the mapbinder.
>
> Below are some half-baked ideas I've pursued; if you already know what
> I mean by reading the above, this part probably will just be
> confusing.
>
> I did see that I can create annotated providers, in answer to a
> question I asked about FactoryModuleBuilder: http://tinyurl.com/2baormz
>
> But it's not clear to me that this gives me the indirection I need to
> bear dynamic fruit.
>
> I also see you can use TypeLiteral with FactoryModuleBuilder.  So
> perhaps I could simply drop the mapbinder altogether and change Fruit
> to be Fruit<T> and let Guice's type mechanism satisfy the type
> injection of FruitFactory<Orange>, but I still lack the indirection
> necessary to obtain a FruitFactory where the fruit class is known only
> at runtime.
>
> Thank you,
> Leigh.
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to