Hi strub, Thanks for the response. I want to use JCDI / OpenWebBeans to manage the lifecycles/injection of my JAX-RS resources/providers. Currently, Wink does the lifecycle management and injection. So if a HTTP request comes in to our RestServlet, we determine which resource class (basically a POJO with @Path) to use, instantiate it, and inject it. What I want to do is to support JSR-299 managed beans here so we get the benefit of the scopes, @Inject support, and other goodies.
I played around a little bit with the Tomcat / OpenEJB / OpenWebBeans integration that Gurkan posted to his blog (cool stuff except I think the patch needed to modify some of the package names with the recent OSGi change; I was going to post back to the OpenEJB issue but I keep getting a 503 Service Unavailable for JIRA). I was thinking I could replace some of our lifecycle management code with calls to the BeanManager. What is the difference between using InjectionTarget calls and the BeanManager.getReference()? I was also looking into using a JCDI Extension to modify the "metadata" to possibly add our own injections for some of the JAX-RS injections but thought I'd tackle the lifecycle questions first. On Wed, May 26, 2010 at 9:52 AM, Bryant Luk <[email protected]> wrote: > 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. >
