OK, Dave and I discussed this a bit and decided to put it to the list for input. Circular dependencies can be hell. ColdSpring has no problems with normal (non-factory) beans, to a point, as long as your beans can be wired together before their are actually used. But this becomes a problem with factories, because a factory needs to be fully configured before it can create the object is creates. Now in many instances, this still doesn't cause to much of a problem. But what does become a problem is if the bean that a factory creates is a dependency of another factory (aop for instance).

Now before everyone gets all worried that we can't apply aop to reactor factory beans, in actuality, we are still OK. In actuality, ColdSpring can still figure out pretty complex situations here. But what gets extra screwy is when a complex relationship like aop'd factories become part of a circular dependency, say if for some crazy reason we decide aspects are dependent on the proxied beans that they also need to be inserted into (Sean!).

OK, so is all hope lost? Actually no. Spring for Java has run into this same issue, obviously, and yes in certain circumstances, they fail. In order to help they have a few other tricks up their sleeves, and one that can be really helpful is an interface, BeanFactoryAware. Implementing this means having a public method setBeanFactory() in your bean. Spring checks that you have implemented the interface and thus knows that instead of meaning your bean wants another bean called 'beanFactory' you actually want the Spring bean factory.

So we will be adding this feature, and now a BeanFactoryAware bean will be able to retrieve it's dependencies itself, in say a setup- method, since that happens AFTER all dependencies have been resolved. In Sean's case, those aspects already have been set up on the proxy bean, which will already have been created by the time the setup- methods are called.

Now I know alot of this sounds a bit confusion, but really it's going to help greatly. But here comes the conundrum. We don't have interfaces, and asking you to extends a BeanFactoryAware bean is not good, since we also don't have multiple inheritance. So here's our options:

first off, you put a setBeanFactory() method in you bean, then you need to tell ColdSpring that you intend this to actually be a BeanFactoryAware bean. You could:

A: add an attribute 'beanFactoryAware' to the xml file for the bean (Which is NOT in the Spring DTD, I don't like it)

B: add an attribute to the <cfcomponent> tag: <cfcomponent name="myBFAComponent" coldSpingBeanFactoryAware="true" ... />

C: have ColdSpring just assume that since you have the method setBeanFactory() in your component, what you mean is that this is
        a BeanFactoryAware bean.

* of course, ColdFusion 8 will have interfaces...

Thoughts??

Chris

Chris Scott
[EMAIL PROTECTED]
http://cdscott.blogspot.com/
http://www.coldspringframework.org/


GIF image







Reply via email to