xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Inject a iterable of bindings of a given type #607

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Actually it is possible to bind instances of a given type to another subtype 
and also to receive this instances in another class constructor. 

I'm facing a scenario where should be very useful to receive a collection of 
bindings of a given type. The scenario I'm facing is this: there's a few 
modules, each one binding one or more Callable<Void> child classes instances. 
One of this modules gonna call all Callables. So, should be great to me to bind 
and inject something like Iterable<Callable<Void>>.

If you guys think this should be interesting to have on guice, I appreciate to 
have this implemented. If there's any other way to have this done on actual 
Guice implementation, I appreciate also to have any link explaining how to to 
this. I already searched before creating this ticket. 

And if there's no way to do this and this scenario wouldn't be interesting to 
be implemented on Guice, that's fine either! :-)

Thanks a lot! 

Original issue reported on code.google.com by feu.tes...@gmail.com on 21 Feb 2011 at 12:47

GoogleCodeExporter commented 9 years ago
I know it is possible to use TypeLiteral to inject Generic code, but it did not 
solve that proposed scenario because some of the bindings gonna be divided 
between different modules.

Thanks a lot again!

Original comment by feu.tes...@gmail.com on 21 Feb 2011 at 12:50

GoogleCodeExporter commented 9 years ago
Would http://code.google.com/p/google-guice/wiki/Multibindings solve this for 
you?

Original comment by sberlin on 21 Feb 2011 at 1:03

GoogleCodeExporter commented 9 years ago
Totally! This solves my problem in a way that I like! Thanks a lot for the fast 
answer and sorry for not found this on the documentation!

Original comment by feu.tes...@gmail.com on 21 Feb 2011 at 1:23

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 22 Feb 2011 at 1:37