-
1. Re: Instance of Component
meetoblivion Apr 20, 2011 10:18 PM (in response to pydesaulle)Probably a better question for the Weld forum. Basically, there is a centralized
BeanManager
object that you would @Inject into your code. Since CDI is essentiallycontextually sensitive
it'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.
ap
stands 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 intoSet<Bean<?>> beans = bm.getBeans(MyType.class); Bean<?> bean = bm.resolve(beans); Object o = bm.getReference(bean,MyType.class,bm.createCreationalContext(null));