[jboss-dev-forums] [Design the new POJO MicroContainer] - Autowire bug on existing target
alesj
do-not-reply at jboss.com
Tue May 20 11:41:34 EDT 2008
I found a bug on my autowiring code. :-)
In case you provide an existing instance when installing bean metadata into Controller (Controller.install(bmd, myinstance)), that instance won't be part of matching contexts since the code that strips down the instance into its class, superclasses, interfaces, ... is in InstantiateAction.
And we skip that action when target already exists.
I'm thinking of adding something like
| public class AutowireAction extends InstallsAwareAction
| {
| protected void installActionInternal(KernelControllerContext context) throws Throwable
| {
| KernelController controller = (KernelController)context.getController();
| DependencyInfo dependencyInfo = context.getDependencyInfo();
| if (dependencyInfo != null && dependencyInfo.isAutowireCandidate())
| controller.addInstantiatedContext(context);
| }
|
| protected void uninstallActionInternal(KernelControllerContext context)
| {
| try
| {
| KernelController controller = (KernelController)context.getController();
| DependencyInfo dependencyInfo = context.getDependencyInfo();
| if (dependencyInfo != null && dependencyInfo.isAutowireCandidate())
| controller.removeInstantiatedContext(context);
| }
| catch (Throwable ignored)
| {
| log.debug("Ignored error unsetting context ", ignored);
| }
| }
|
| protected ControllerState getState()
| {
| return ControllerState.INSTANTIATED;
| }
|
| protected Class<? extends KernelControllerContextAware> getActionAwareInterface()
| {
| return InstantiateKernelControllerContextAware.class;
| }
| }
and then fix the KernelControllerContextActions to have this
| actions.put(ControllerState.INSTANTIATED, new AutowireAction());
|
And this also addresses this issue, e.g. you wanted to have some install callback in INSTANTIATE action, that wouldn't be triggered either, since we would skip that state. ;-)
OK?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152071#4152071
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152071
More information about the jboss-dev-forums
mailing list