To solve this you're able to bind the Factory using FactoryModule builder,
and then add it to the map.

class Car {
  @Inject Car(@Assisted Color color) { ...}

  interface CarFactory {
     Car create(Color color);
  }
}

And let's say you want a map that gives you:
 "green" => new Car(Color.GREEN)
 "blue" => new Car(Color.BLUE)

install(new FactoryModuleBuilder().
   .build(Key.get(CarFactory.class, Names.named("CreatesGreenCars"));


install(new FactoryModuleBuilder().
   .build(Key.get(CarFactory.class, Names.named("CreatesBlueCars"));

MapBinder<Color, CarFactory> mapBinder =
  MapBinder.newMapBinder(binder(), Color.class, CarFactory.class);
mapBinder.addBinding(Color.GREEN)
  .to(Key.get(CarFactory.class, Names.named("CreatesGreenCars"));
mapBinder.addBinding(Color.BLUE)
  .to(Key.get(CarFactory.class, Names.named("CreatesBlueCars"));

That will give you what you're looking for, I believe.

There's some boilerplate that a method or two could reduce e.g., Key
getKey(Color color) { ...}

-Fred


On Mon, Jan 10, 2011 at 11:22 AM, kimchy <[email protected]> wrote:

> Hi,
>
>   Wondering how to use the new assisted inject with MapBinder, now that
> FactoryProvider is deprecated? For example, how to code
> this: mapBinder.addBinding(name).toProvider(FactoryProvider...) ?
>
> cheers,
> -shay.banon
>
> --
> 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