Re: ambiguous dependencies when using multiple qualifiers
OK, thanks for the clarification! Regards, Jakob 2010/9/29 Joseph Bergmark bergm...@apache.org: I think you hit the nail on the head with your last paragraph. Basically it only matters that the bean (or producer in this case) matches all of the qualifiers on the injection point. From the perspective of the specification it doesn't matter if the bean has extra qualifiers beyond those on the injection point. Section 5.3 is another key section here. Sincerely, Joe On Wed, Sep 29, 2010 at 12:30 PM, Jakob Korherr jakob.korh...@gmail.com wrote: Hi, I tested some scenarios when using multiple qualifiers for test-cases in MyFaces CODI and stumbled upon the following scenario, which is not totally clear to me. Image you have the following producer methods: �...@produces �...@qualifier2 �...@applicationscoped public ProducerBean createWithQualifier2() { return new ProducerBean(); } �...@produces �...@qualifier1 �...@qualifier2 �...@applicationscoped public ProducerBean createWithQualifier1And2() { return new ProducerBean(); } and you want to inject the instances produced by these producers. Now you can use @Inject @Qualifier1 or @Inject @Qualifier1 @Qualifier2, but when using @Inject @Qualifier2 you will get an exception, because the injection point is ambiguous (both producers provide @Qualifier2). However I was wondering if this is really unresolvable ambiguous, because if you think about it, it would make sence to take the producer createWithQualifier2() in this scenario (because the other one provides additional qualifiers). I also took a look in the CDI spec about this, but could only find the following from section 2.3.4: A bean may only be injected to an injection point if it has all the qualifiers of the injection point. Of course this applies to both producers and thus, yes, it's kinda ambiguous. WDYT? Regards, Jakob -- Jakob Korherr blog: http://www.jakobk.com twitter: http://twitter.com/jakobkorherr work: http://www.irian.at -- Jakob Korherr blog: http://www.jakobk.com twitter: http://twitter.com/jakobkorherr work: http://www.irian.at
Re: ambiguous dependencies when using multiple qualifiers
I also took a look in the CDI spec about this, but could only find the following from section 2.3.4: A bean may only be injected to an injection point if it has all the qualifiers of the injection point. Of course this applies to both producers and thus, yes, it's kinda ambiguous. When an ambiguous dependency exists, the container attempts to resolve the ambiguity. The container eliminates all eligible beans that are not alternatives, except for producer methods and fields of beans that are alternatives. If there is exactly one bean remaining, the container will select this bean, and the ambiguous dependency is called resolvable. The spec says both producers satisfy the injection point, and does not allow it to discard the one with additional qualifiers. -- Eric Covener cove...@gmail.com
Re: ambiguous dependencies when using multiple qualifiers
I think you hit the nail on the head with your last paragraph. Basically it only matters that the bean (or producer in this case) matches all of the qualifiers on the injection point. From the perspective of the specification it doesn't matter if the bean has extra qualifiers beyond those on the injection point. Section 5.3 is another key section here. Sincerely, Joe On Wed, Sep 29, 2010 at 12:30 PM, Jakob Korherr jakob.korh...@gmail.com wrote: Hi, I tested some scenarios when using multiple qualifiers for test-cases in MyFaces CODI and stumbled upon the following scenario, which is not totally clear to me. Image you have the following producer methods: �...@produces �...@qualifier2 �...@applicationscoped public ProducerBean createWithQualifier2() { return new ProducerBean(); } �...@produces �...@qualifier1 �...@qualifier2 �...@applicationscoped public ProducerBean createWithQualifier1And2() { return new ProducerBean(); } and you want to inject the instances produced by these producers. Now you can use @Inject @Qualifier1 or @Inject @Qualifier1 @Qualifier2, but when using @Inject @Qualifier2 you will get an exception, because the injection point is ambiguous (both producers provide @Qualifier2). However I was wondering if this is really unresolvable ambiguous, because if you think about it, it would make sence to take the producer createWithQualifier2() in this scenario (because the other one provides additional qualifiers). I also took a look in the CDI spec about this, but could only find the following from section 2.3.4: A bean may only be injected to an injection point if it has all the qualifiers of the injection point. Of course this applies to both producers and thus, yes, it's kinda ambiguous. WDYT? Regards, Jakob -- Jakob Korherr blog: http://www.jakobk.com twitter: http://twitter.com/jakobkorherr work: http://www.irian.at