-
1. Re: Factories with Optional @Qualifiers, @Stereotypes and @Produces, How?
luksa Feb 29, 2012 7:11 AM (in response to ahhughes)Just make the producer method like this:
@Produces public Widget produceWidget(InjectionPoint injectionPoint);
The injectionPoint argument will contain the metadata of the field that is being injected. The producer method can therefore inspect the annotations of that field and produce the widget according to the annotations.
Look at the HttpParams example at http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html_single/#d0e1624
-
2. Re: Factories with Optional @Qualifiers, @Stereotypes and @Produces, How?
ahhughes Mar 26, 2012 7:23 PM (in response to luksa)Hi Marko,
Thanks for your reply. I had hoped for a different answer, I am dissapointed. The reason is this... there is nothing in CDI to ensure that the resolved @Produces will have any consideration for the Injection Point's unique combination of qualifiers. Perhaps this is actually seen as an advantage?
So why am I saying all this...
After experiencing both Guice and CDI I can see several pro's/con's between the two. Like a kid in a candy store, Guice's @Assisted injection is just too damn good - I want it, I want it.... It's capability to realize a super clean and type safe factory pattern with almost zero effort is brilliant. Not to mention the fact that it can take in supplied (non primitive) arguments.
If there is a better way to realize this, or if someone can explain it better can I suggest we start an article (or some form of documentation) to help out as many people as we can to explain recommended solutions?
CHEERS