On Thu, Nov 20, 2014 at 9:42 PM, Jozef Hartinger <jharting@redhat.com> wrote:
The simplest thing you can do is:

Bean<InjectionPoint> bean = (Bean<InjectionPoint>) manager.resolve(manager.getBeans(InjectionPoint.class));
InjectionPoint ip = (InjectionPoint) manager.getReference(bean, InjectionPoint.class, manager.createCreationalContext(bean));

I just tried this again, and unfortunately it now fails on Weld.

I quickly tried a series of Weld versions and this is the result:

2.2.6 works
2.2.8 works
2.2.9 fails
2.2.13 fails
2.2.14 fails
2.2.16 fails
2.3.0 fails
2.3.2 fails

So apparently it broke between 2.2.8 and 2.2.9.

Would it be possible to add a TCK test for this? This would be really helpful as we'd like to use this for the JSF 2.3 RI.

Kind regards,
Arjan Tijms


On 11/19/2014 05:06 PM, arjan tijms wrote:

In a producer method it's trivial to get access to an InjectionPoint
instance representing the point where the value produced by the
producer will be injected.

When registering a Bean manually from an extension using
AfterBeanDiscovery#addBean, this is not immediately obvious.

After some fumbling with the CDI APIs I came up with the following
code that seems to work on both Weld and OWB (didn't test CanDI yet).

It uses a small "dummy" class, which is used to grab an InjectionPoint off:

In a Bean:

public Object create(CreationalContext<Object> creationalContext) {

InjectionPoint injectionPoint = (InjectionPoint)

With InjectionPointGenerator being the following class:

public class InjectionPointGenerator {
     private InjectionPoint injectionPoint;

And resolve being the following method:

public static <T> Bean<T> resolve(BeanManager beanManager, Class<T> beanClass) {
         Set<Bean<?>> beans = beanManager.getBeans(beanClass);

         for (Bean<?> bean : beans) {
             if (bean.getBeanClass() == beanClass) {
                 return (Bean<T>)

         return (Bean<T>) beanManager.resolve(beans);

As mentioned, while this seems to work, I wonder if it's the best approach.

Kind regards,
cdi-dev mailing list

Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.