Hi, I was looking to create managed bean instances dynamically for an Apache Wink (JAX-RS) plugin.
I found the BeanManager interface and was hoping that would be a good way to get my instances via a programmatic interface. Is that a possible route for me to take? So pseudcode-ish, I would do: BeanManager beanManager = ... Class<T> managedBeanClass = ... AnnotatedType aType = beanManager.createAnnotatedType(managedBeanclass); InjectionTarget<T> iTarget = beanManager.createInjectionTarget(aType); /* is this the way to get the right creational context? */ Set<Bean<?>> beans = beanManager.getBeans(managedBeanClass, (any qualifier annotations here)); Bean bean = beans.iterator().next(); CreationalContext creationalContext = beanManager.createCreationalContext(bean); T instance = iTarget.produce(creationalContext); iTarget.inject(instance, creationalContext); iTarget.postConstruct(instance); /* ...use the instance... */ iTarget.preDestroy(instance); iTarget.dispose(instance); /* do I need to do a creationalContext.release()? */ I'm hoping the created instance will be correctly injected/disposed of and would be correctly scoped (i.e. if it's in a servlet container and the managed bean was @ApplicationScoped then the above code would still "do the right thing" instead of creating a new instance). Thanks for any pointers anyone can provide.
