[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: expressing dependent states
adrian@jboss.org
do-not-reply at jboss.com
Wed May 21 12:07:20 EDT 2008
"jhalliday" wrote : Hmm, presumably injecting it as a parameter to some lifecycle method ensures the property has actually been configured correctly (ORBService may setORB(...) in e.g. startService()), whereas injecting it as a property on the bean does not. Property injection is built on the assumption that a bean's properties are initialized at bean creation time I guess? Besides, if I inject it as a property of my bean, I may be tempted to use it in create() rather than start(), which would be against the guidelines I think. So the correct approach would seem to be
|
No. "inject" is different from "depends".
The MC is a lot more flexible than the old service lifecycle.
In fact, the JBoss5 service lifecycle is more flexible than the old JBoss4 one. ;-)
depends is a two phase lifecycle create/start that is backwards compatible with
the old MBean service lifecycle.
The MBean lifecycle was originally done as two phase to solve circular dependency
issues (which most services don't have anyway ;-).
inject works by requiring the dependency is INSTALLED (i.e. it has completed its whole
lifecycle) before the object can be injected into the dependee.
Circular dependencies are handled in a different (more explicit) way in the MC,
see the getting started docs. i.e. You can override what state the dependency
must be in before it is injected.
e.g. You can inject an MBean instance or property into a constructor, propertly, lifecycle
method parameter, etc. and it will guarantee the MBean has been fully started before
that part of the lifecycle gets invoked.
There's a different philosophy between the two mechanisms.
ASIDE:
In JBoss5 MBeans have gained some (but not all) of this injection flexibility
from the ServiceController being implemented on top of the MC.
e.g. There is now a proper lifecycle for the setAttribute() invocations on the
mbeans so they can use "inject" semantics rather than "depends optional-attribute".
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152414#4152414
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152414
More information about the jboss-dev-forums
mailing list