I have a MapBinder as below in my Module:
MapBinder<String, IFoo> mapBinder =
MapBinder.newMapBinder(binder(), String.class,
IFoo.class);
mapBinder.addBinding(Bar.ONE).to(FooOne.class);
mapBinder.addBinding(Bar.TWO).to(FooTwo.class);
This works great and the IFoo implementations can be retrieved like
so:
private final Map<String, IFoo> foos;
@Inject
public FooMap(Map<String, ICommand> foos) {
this.foos = foos;
}
public void doSomething(IBar b) {
IFoo foo = foos.get(b.getType());
foo.execute();
}
I'd like to have the parameter of the 'doSomething' method be
@Assisted into the Foo that comes out of the map. I think you can do
it with a FactoryProvider for each IFoo implementation. Is it possible
to have a single FactoryProvider handle the creation. Could I inject
the foos map in a Factory and have them come out with an @Assisted
IBar instance in them?
thanks!
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Thanks for that, it works great. One more question and again not sure
if this is possible, I'm new to Java and Guice, right now I have:
public class FooOne implements IFoo {
private final BarA _barA;
@Inject
public FooOne(@Assisted IBar bar) {
this._bar = (BarA)bar;
}
@Override
public void doSomething() {
// do something with _barA...
}
}
In the above I cast the @Assisted IBar to the BarA implementation
(there could be many IBar impl: BarA, BarB, BarC), is there a way to
avoid the cast?
> > google-guice...@googlegroups.com<google-guice%2Bunsubscribe@google groups.com>
http://github.com/kreek/Commad-Pattern-with-Guice
On May 26, 4:51 pm, Kartik Kumar <krishnan.1...@gmail.com> wrote:
> > google-guice...@googlegroups.com<google-guice%2Bunsubscribe@google groups.com>
To unsubscribe from this group, send email to google-guice...@googlegroups.com.