[cdi-dev] [JBoss JIRA] (CDI-471) Support repeating qualifiers in typesafe resolution mechanism

John Ament (JIRA) issues at jboss.org
Thu Sep 8 06:29:00 EDT 2016


    [ https://issues.jboss.org/browse/CDI-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13290412#comment-13290412 ] 

John Ament edited comment on CDI-471 at 9/8/16 6:28 AM:
--------------------------------------------------------

Ok, then we need to make sure the spec wording states that they behave like any other qualifier.  Meaning if I had the following producers:

{code}
@Produces @ContextName("ctx1") ProducerTemplate pt1;
@Produces @ContextName("ctx2") ProducerTemplate pt2;
{code}

And an injection point:

{code}
@inject
@ContextName("ctx1")
@ContextName("ctx2")
private ProducerTemplate pt;
{code}

I would get no beans satisfying..

likewise, if I had the following producers:

{code}
@Produces @ContextName("ctx1") ProducerTemplate pt1;
@Produces @ContextName("ctx2") ProducerTemplate pt2;
@Produces @ContextName("ctx1") @ContextName("ctx2") ProducerTemplate pt;
{code}

and injection points:

{code}
@inject
@ContextName("ctx1")
@ContextName("ctx2")
private ProducerTemplate pt0;

@inject
@ContextName("ctx1")
private ProducerTemplate pt1;

@inject
@ContextName("ctx2")
private ProducerTemplate pt2;
{code}

The first injection point would work fine, however the second and third would give an ambiguous bean resolution, as behaves today.


was (Author: meetoblivion):
Ok, then we need to make sure the spec wording states that they behavior like any other qualifier.  Meaning if I had the following producers:

{code}
@Produces @ContextName("ctx1") ProducerTemplate pt1;
@Produces @ContextName("ctx2") ProducerTemplate pt2;
{code}

And an injection point:

{code}
@inject
@ContextName("ctx1")
@ContextName("ctx2")
private ProducerTemplate pt;
{code}

I would get no beans satisfying..

likewise, if I had the following producers:

{code}
@Produces @ContextName("ctx1") ProducerTemplate pt1;
@Produces @ContextName("ctx2") ProducerTemplate pt2;
@Produces @ContextName("ctx1") @ContextName("ctx2") ProducerTemplate pt;
{code}

and injection points:

{code}
@inject
@ContextName("ctx1")
@ContextName("ctx2")
private ProducerTemplate pt0;

@inject
@ContextName("ctx1")
private ProducerTemplate pt1;

@inject
@ContextName("ctx2")
private ProducerTemplate pt2;
{code}

The first injection point would work fine, however the second and third would give an ambiguous bean resolution, as behaves today.

> Support repeating qualifiers in typesafe resolution mechanism
> -------------------------------------------------------------
>
>                 Key: CDI-471
>                 URL: https://issues.jboss.org/browse/CDI-471
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Resolution
>            Reporter: Antonin Stefanutti
>              Labels: F2F2016
>             Fix For: 2.0 (proposed)
>
>
> As Java 8 provides improved support for [repeating annotations|http://docs.oracle.com/javase/tutorial/java/annotations/repeating.html], it would be valuable to percolate that support into the CDI typesafe resolution mechanism.
> For example, one could write:
> {code}
> @Qualifier
> @Repeatable(ContextNames.class)
> public interface @ContextName {
>     String value;
> }
> public @interface ContextNames {
>     ContextName[] value();
> }
> {code}
> And then:
> {code}
> @ContextName("ctx1")
> class CamelContext1 {
> }
> @ContextName("ctx2")
> class CamelContext2 {
> }
> @Uri("")
> @Produces
> @ContextName("ctx1")
> @ContextName("ctx2")
> static ProducerTemplate producerTemplate(InjectionPoint ip, @Any Instance<CamelContext> instance) {
> }
> {code}
> That enables to use annotations both as a CDI qualifiers and a metadata providers while still be relying on standard typesafe resolution mechanism during the deployment phase to detect unsatisfied or ambiguous dependencies.
> Support of the annotation container / list for backward compatibility could be provided as well.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list