Thanks for the idea Sam.

Actually, I found another solution which works great in my situation. I had 
this idea by looking at the code for the assisted factories, 
com.google.inject.assistedinject
.FactoryProvider2 in particular.

- The modules bind instances of Class<? extends ISomeInterface> (it's a 
little bit more complex then that, as they actually bind wrapper objects 
with a name (a String) in addition to the Class itself)
- I have an object "MyMetaFactory" that as a constructor that is injected 
with the Set<Class<? extends ISomeInterface>> from the multibinding, and 
with the Injector itself.
- In this MyMetaFactory's constructor, I create a *child injector* using an 
anonymous Module which creates assisted factories for each of the 
ISomeInterfaces.
- All assisted factories, created using the child injector, are stored in a 
MyMetaFactory's local variable. So when the MyMetaFactory's constructor 
exits, all the required assisted factories are created.
- Then, the rest of the code will use MyMetaFactory to get an instance of 
the particular ISomeInterface they need (by passing its "name", remember 
that was also multibinded!). MyMetaFactory will uses the appropriate 
assisted factory to create the instance.

I'm pretty happy with this pattern (How do you call it? The "AssistedInject 
Multibindings" pattern ?)

-- 
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/groups/opt_out.


Reply via email to