<div dir="ltr">Hi<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 9:42 PM, Jozef Hartinger <span dir="ltr">&lt;<a href="mailto:jharting@redhat.com" target="_blank">jharting@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The simplest thing you can do is:<br>
<br>
Bean&lt;InjectionPoint&gt; bean = (Bean&lt;InjectionPoint&gt;) manager.resolve(manager.getBeans(InjectionPoint.class));<br>
InjectionPoint ip = (InjectionPoint) manager.getReference(bean, InjectionPoint.class, manager.createCreationalContext(bean));</blockquote><div><br></div><div>I just tried this again, and unfortunately it now fails on Weld.</div><div><br></div><div>I quickly tried a series of Weld versions and this is the result:</div><div><br></div><div><div>Weld</div><div>2.2.6 works</div><div>2.2.8 works</div><div>2.2.9 fails</div><div>2.2.13 fails</div><div>2.2.14 fails</div><div>2.2.16 fails</div><div>2.3.0 fails</div><div>2.3.2 fails</div></div><div><br></div><div>So apparently it broke between 2.2.8 and 2.2.9.</div><div><br></div><div>Would it be possible to add a TCK test for this? This would be really helpful as we&#39;d like to use this for the JSF 2.3 RI.</div><div><br></div><div>Kind regards,</div><div>Arjan Tijms</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5"><br>
<br>
On 11/19/2014 05:06 PM, arjan tijms wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5">
Hi,<br>
<br>
In a producer method it&#39;s trivial to get access to an InjectionPoint<br>
instance representing the point where the value produced by the<br>
producer will be injected.<br>
<br>
When registering a Bean manually from an extension using<br>
AfterBeanDiscovery#addBean, this is not immediately obvious.<br>
<br>
After some fumbling with the CDI APIs I came up with the following<br>
code that seems to work on both Weld and OWB (didn&#39;t test CanDI yet).<br>
<br>
It uses a small &quot;dummy&quot; class, which is used to grab an InjectionPoint off:<br>
<br>
In a Bean:<br>
<br>
public Object create(CreationalContext&lt;Object&gt; creationalContext) {<br>
<br>
InjectionPoint injectionPoint = (InjectionPoint)<br>
beanManager.getInjectableReference(<br>
             resolve(beanManager,<br>
InjectionPointGenerator.class).getInjectionPoints().iterator().next(),<br>
creationalContext<br>
);<br>
<br>
With InjectionPointGenerator being the following class:<br>
<br>
public class InjectionPointGenerator {<br>
     @Inject<br>
     private InjectionPoint injectionPoint;<br>
}<br>
<br>
And resolve being the following method:<br>
<br>
public static &lt;T&gt; Bean&lt;T&gt; resolve(BeanManager beanManager, Class&lt;T&gt; beanClass) {<br>
         Set&lt;Bean&lt;?&gt;&gt; beans = beanManager.getBeans(beanClass);<br>
<br>
         for (Bean&lt;?&gt; bean : beans) {<br>
             if (bean.getBeanClass() == beanClass) {<br>
                 return (Bean&lt;T&gt;)<br>
beanManager.resolve(Collections.&lt;Bean&lt;?&gt;&gt;singleton(bean));<br>
             }<br>
         }<br>
<br>
         return (Bean&lt;T&gt;) beanManager.resolve(beans);<br>
     }<br>
<br>
As mentioned, while this seems to work, I wonder if it&#39;s the best approach.<br>
<br>
Kind regards,<br>
Arjan<br></div></div>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
</blockquote>
<br>
</blockquote></div><br></div></div>