Map binder with assisted inject factories

30 views
Skip to first unread message

Matt Mitchell

unread,
Jun 12, 2016, 6:37:16 PM6/12/16
to google-guice
I'd like to do something like:

interface Thing{}


class ThingA implements Thing{
 
 
@AssistedInject
 
public ThingA(@Assisted String something, SomeOtherDependencyManagedByGuice foo){
    // ...
 
}
 
}


// need a factory for ThingA and ThingB? What does this/these look like?


public MyApp(Map<String,ThingFactory> f){
 
ThingA thing = g.get('thing-type-a").create("something");
}



In that case, "thing-type-a" is a String/Key pointing to some factory instance in the map (used for creating a ThingA), and "something" is a user-assisted/runtime argument to the factory "create" method. I have map binding working with a factory but how do I then get assisted inject to work on the actual implementations of Thing? Could someone post a full example of how to do this? I can't seem to find a complete working example of how to do this.

Thanks,
- Matt
Reply all
Reply to author
Forward
0 new messages