It's hard sight-unseen, as I don't really know your code and it's context.

One way would be to have a module that takes a list of Class<H> and then, in the configure method, loops through all H types and looks up T's and registers them in a MapBinder.

But that's off the top of my head. How you get the list of H's is kind of up to you. You could generate such a list with an annotation processor.

You could maybe also make the H annotations (they are annotations, right?) a Qualifier annotation, and then not even use a MapBinder, but just make all your T's be annotated with H annotations of the appropriate type, and have an @Injectable constructor and private modules per the robot legs example.

http://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions#How_do_I_build_two_similar_but_slightly_different_trees_of_objec

Again - I'm not sure what the "right" way to do this here is. Your specific code will vary. I'm not even 100% sure what you need to inject vs. register, as sometimes a system that has a registry like you described can be re-designed to just let guice take care of this process for you. I'm afraid you'll have to make some of these judgments for yourself.

Christian.

On 9 Dec 2012, at 17:11, paweł kamiński wrote:

well thats true, but I want to make it easy at first place and if this turn
to be inefficient then I will optimize.
basically I can do that once per application startup, so I don't care too
much for now.

can you show me more how such module could look like?

On Sunday, December 9, 2012 9:59:54 PM UTC+1, Christian Gruber wrote:

I think I'd need to see more of what you are trying to do - if you're
really mapping T's to H's then there has to be some place that the
mapping is maintained. You could create a custom module that registers
a Provider of HX for TX for all available T/Hs.  But it would have to
scan (presumably) for T/s and H/s and that can be performance affecting.

The more automatic your discovery is, the more issues you can
potentially have with things sort of getting a bit inobvious, and
possibly negative for performance.  Just be balanced and consider the
trade-offs.

Christian.


On 8 Dec 2012, at 11:11, paweł kamiński wrote:

hey, I ve already answered my own question few hours ago , so I guess
it
waits for moderation.
yes multibinding is a way to go, is there a way to automatically
configure
it so I dont need to add all H* classes by hand?

thanks anyway.

On Saturday, December 8, 2012 4:56:54 PM UTC+1, Christian Gruber
wrote:

You might want to look at MapBinder.

On Friday, 7 December 2012, paweł kamiński wrote:

<
http://stackoverflow.com/questions/13670060/guice-return-set-of-instances-with-custom-annotation#>


I have very simple scenario where class A registers instances for
types.

A.register(T1.class, new H1());
A.register(T2.class, new H2());

this is fairly simple configuration when done by hand but guice
injection
doesn't work when I create instances outside the guice framework.

I try to figure out how to create and configure A with all instance
with
custom annotation using guice. is guice even prepared for that?

I know that in java it is possible to use
javax.enterprise.inject.Instance to get all instances of type (and
optionally annotated with custom annotation) but I dont want to use
this if
possible.

thanks for any help

--
You received this message because you are subscribed to the Google
Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/sAMvg3woPCUJ.
To post to this group, send email to [email protected]<javascript:>.

To unsubscribe from this group, send email to
[email protected] <javascript:>.
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 view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/-jbVt_5a8sgJ.
To post to this group, send email to [email protected]<javascript:>.

To unsubscribe from this group, send email to
[email protected] <javascript:>.
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 view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/9JRBsinA50wJ.
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.

--
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