Probably a better question for the Weld forum. Basically, there is a centralized
BeanManagerobject that you would @Inject into your code. Since CDI is essentially
contextually sensitiveit's a few extra steps, but you'd be looking at some code like this:
Set<Bean<?>> beans = bm.getBeans(MyType.class); Bean<?> bean = bm.resolve(beans); ImmutableInjectionPoint iip = new ImmutableInjectionPoint(ap,bm,bean,false,false); Object o = bm.getInjectableReference(iip, bm.createCreationalContext(bean));
This uses the ImmutableInjectionPoint class from Seam Solder.
apstands for AnnotatedParameter, essentially a method parameter. There are a few other constructor types that you can use here though, depending on what you need, for the most part you probably want the getReference method http://download.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html#getReference%28javax.enterprise.inject.spi.Bean,%20java.lang.reflect.Type,%20javax.enterprise.context.spi.CreationalContext%29 and you can pass in null to the createCreationalContext method http://download.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html#createCreationalContext%28javax.enterprise.context.spi.Contextual%29 which turns my example into
Set<Bean<?>> beans = bm.getBeans(MyType.class); Bean<?> bean = bm.resolve(beans); Object o = bm.getReference(bean,MyType.class,bm.createCreationalContext(null));