[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Web beans on top of Microcontainer deployment order
kabir.khan@jboss.com
do-not-reply at jboss.com
Thu Aug 13 13:23:17 EDT 2009
I have a prototype of WB -> MC injection working now. The core of it is this class which is a modified version of http://www.seamframework.org/Documentation/HowDoIDoNoncontextualInjectionForAThirdpartyFramework
| public class WebBeansInjector<T> {
|
| private final InjectionTarget<T> it;
| private CreationalContext<T> creationalContext;
|
| WebBeansInjector(BeanManager manager, Class<T> clazz) {
| AnnotatedType<T> type = manager.createAnnotatedType(clazz);
| it = manager.createInjectionTarget(type);
| creationalContext = manager.createCreationalContext(null);
| }
|
| Set<InjectionPoint> getInjectionPoints()
| {
| return it.getInjectionPoints();
| }
|
| T instantiate()
| {
| T t = it.produce(creationalContext);
| return t;
| }
|
| void inject(Object instance)
| {
| it.inject((T)instance, creationalContext);
| }
|
| void postConstruct(Object instance) {
| it.postConstruct((T)instance);
| }
|
| void preDestroy(T instance) {
| it.preDestroy(instance);
| creationalContext.release();
| }
| }
|
If we deploy the following class as an MC bean
| class McBeanUsingWebBeans{
| @Current SomeWebBean someWebBean;
|
| @Current AnotherWebBean anotherWebBean;
|
| McUsingWebBeans(@Current AnotherWebBean anotherWebBean){
| this.anotherWebBean = anotherWebBean;
| }
| }
|
This is wrapped up in a custom KernelControllerContext (WebBeansKernelControllerContext). It uses some custom actions:
*** WebBeansDescribeAction extends DescribeAction
Delegates to the super DescribeAction for the normal MC describe functionality. It creates the WebBeansInjector and sets that in the context. It then calls WBI.getInjectionPoints() and for each injection point creates a WebBeansDependencyMetaData that is added to the context's BeanMetaData.
TODO: Remove the dependencies on uninstall
*** WebBeansInstantiateAction extends InstantiateAction
Calls WBI.instantiate() which instantiates the bean with constructor injection of the beans found in web beans, and sets the context's target.
TODO: Some more checks here to see if the constructor should have web beans injection (use current WBI instantiation mechanism) or MC injection of parameters (use MC instantiation mechanism). I don't think we can mix and match the injection models here, meaning we can't have a constructor with some parameters from web beans and others with parameters from MC?
*** WebBeansConfigureAction extends ConfigureAction
Delegates to the super ConfigureAction for the normal MC configuration of properties. It then calls WBI.inject, which inject the web beans into the properties.
TODO: Null out the web beans fields on uninstall manually since web beans does not provide this for us
TODO: Test with setter injection
*** WebBeansPostConstructAction ???
I need to invoke WBI.postConstruct()/preDestroy() from somewhere, but am unsure if I should do that as part of CREATE, START or if I need a new state. If I need a new state, where should that go?
The WebBeansDependencyMetaData ends up as a WebBeansDependencyItem, which has reference to a InjectionPoint. It's resolve method delegates checking if the dependency is satisfied by delegating to the Web Beans BeanManager:
| public boolean resolve(Controller controller)
| {
| try
| {
| context.getManager().validate(injectionPoint);
| setIDependOn(injectionPoint);
| // addDependsOnMe(controller, context);
| setResolved(true);
| }
| catch(ValidationException e)
| {
| setResolved(false);
| }
|
| return isResolved();
| }
|
TODO: Some tests for unsatisfied dependencies
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249487#4249487
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4249487
More information about the jboss-dev-forums
mailing list