<div dir="ltr">Hi,<div><br></div><div>When writing an alternative producer, e.g.</div><div><br></div><div><div>@Alternative</div><div>@Priority(500)</div><div>@ApplicationScoped</div><div>public class ApplicationInit {</div><div>     </div><div>    @Produces</div><div>    public HttpAuthenticationMechanism produce(BeanManager beanManager) {</div><div>        return ...</div><div>    }</div></div><div>}</div><div><br></div><div>You not rarely need the bean the producer is going to be an alternative for. For instance to wrap it, or otherwise augment it, or perhaps to take a few values from.</div><div><br></div><div>In order to get that bean, a bunch of quite verbose code is needed. I.e I came up with:</div><div><br></div><div><div>HttpAuthenticationMechanism mechanism =</div><div>    createRef(</div><div>        beanManager.resolve(</div><div>            beanManager.getBeans(HttpAuthenticationMechanism.class)</div><div>                       .stream()</div><div>                       .filter(e -&gt; !e.getBeanClass().equals(ApplicationInit.class))</div><div>                       .collect(toSet())), </div><div>            beanManager);</div></div><div><br></div><div><br></div><div>And:</div><div><br></div><div><div>HttpAuthenticationMechanism createRef(Bean&lt;?&gt; bean, BeanManager beanManager) {</div><div>    return (HttpAuthenticationMechanism) </div><div>        beanManager.getReference(</div><div>            bean, </div><div>            HttpAuthenticationMechanism.class, </div><div>            beanManager.createCreationalContext(bean));</div><div>}</div></div><div><br></div><div>I wonder if it would not be a good idea to introduce something to get that original bean more easily, i.e. just like a decorator and @Delegate.</div><div><br></div><div>E.g.</div><div><br></div><div><div>@Alternative</div><div>@Priority(500)</div><div>@ApplicationScoped</div><div>public class ApplicationInit {</div><div>     </div><div>    @Produces</div><div>    public HttpAuthenticationMechanism produce(BeanManager beanManager, HttpAuthenticationMechanism original) {</div><div>        return ...</div><div>    }</div><div>}</div></div><div><br></div><div>Or reuse the @Delegate (perhaps with the @Alternative annotation)</div><div><br></div><div><div>@Alternative</div><div>@Priority(500)</div><div>@ApplicationScoped</div><div>public class ApplicationInit {</div><div><br></div><div>    @Inject</div><div>    @Delegate</div><div>    @Alternative (?)</div><div>    private HttpAuthenticationMechanism original;</div><div>     </div><div>    @Produces</div><div>    public HttpAuthenticationMechanism produce(BeanManager beanManager) {</div><div>        return ...</div><div>    }</div><div>}</div></div><div><br></div><div>Thoughts?</div><div><br></div><div>Kind regards,</div><div>Arjan Tijms</div></div>