[cdi-dev] Alternative producer methods

Pete Muir pmuir at redhat.com
Mon Apr 2 06:17:24 EDT 2012


Correct.

In fact, it should have no effect on injection of OtherDings at all whether you annotated MyClassContainsProd or not...

On 2 Apr 2012, at 11:14, Mark Struberg wrote:

> Hi Pete!
> Ok, summing up your elaboration means that
> 
> public class MyClassContainsProd {
>   public @Produces @Alternative OtherDings createOtherDings() {
>     return new OtherDings();
>   }
> 
> 
> is perfectly fine and 'MyClassContainsProd' doesn't need to be annotated as @Alternative, right?
> 
> LieGrue,
> strub
> 
> 
> 
> ----- Original Message -----
>> From: Pete Muir <pmuir at redhat.com>
>> To: Mark Struberg <struberg at yahoo.de>
>> Cc: cdi-dev <cdi-dev at lists.jboss.org>
>> Sent: Monday, April 2, 2012 11:30 AM
>> Subject: Re: [cdi-dev] Alternative producer methods
>> 
>> Right now, I can't find a better path through the spec to explain this, if 
>> anyone knows, then say, if not we should clarify for CDI 1.1
>> 
>> Looking at 11.1 getBeanClass() you can see that the bean class of a producer 
>> method (or field) is the class of the bean declaring the producer method (or 
>> field). This should probably be actually specified, rather than just in a 
>> interface description!
>> 
>> From this, we can use Mark's reference to 5.1.1 to see that when we want to 
>> enable an alternative producer, we in fact use the bean class name.
>> 
>> 
>> 
>> On 1 Apr 2012, at 14:51, Mark Struberg wrote:
>> 
>>> Dear EG colleagues!
>>> 
>>> 
>>> I have a question about @Alternative on producer methods:
>>> consider the following class:
>>> 
>>> // here is NO alternative annotation!
>>> 
>>> public class AlternativeOnProducerMethodOnlyBean {
>>>     @Produces  @Alternative
>>>     public IProducedBean generateBean2() {..}
>>> }
>>> 
>>> So the class itself is NOT annotated as @Alternative
>>> 
>>> I'm not sure if 5.1.1 allows this or the other way around: if this must 
>> be supported.
>>> 
>>> Imo the important parts are (from 5.1.1)
>>>> Each child <class> element must specify the name of an 
>> alternative bean class. 
>>> 
>>>> If there is no class with the specified name, or if the class with the 
>> specified 
>>> 
>>>> name is not an alternative bean class, the container automatically 
>> detects 
>>> 
>>>> the problem and treats it as a deployment problem.
>>> 
>>> The question is now how 'an alternative bean class' is to be 
>> interpreted ^^
>>> The first paragraph of 5.1.1 says:
>>> 
>>>>    An alternative is selected for the bean archive if either ...
>>>> * the alternative is a producer method, field or resource, and the 
>>> 
>>>> bean class that declares the method or field is listed, ...
>>> 
>>> 
>>> But does this qualify the AlternativeOnProducerMethodOnlyBean as 
>> 'alternative bean class'?
>>> 
>>> Any ideas?
>>> 
>>> Btw: the whole topic of disposal methods for @Alternative producers are 
>> completely unspecified...
>>> 
>>> LieGrue,
>>> strub
>>> 
>>> _______________________________________________
>>> cdi-dev mailing list
>>> cdi-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/cdi-dev
>> 




More information about the cdi-dev mailing list