This is called making a bean 'BeanFactoryAware'. In Spring, you would do this by implementing the BeanFactoryAware interface, as you will do in the CF8 version of ColdSpring. For the current version, we have taken a duck-typing approach, so all you need to do is add this method:

<cffunction name="setBeanFactory" returntype="void" access="public" output="false">
<cfargument name="bf" type="coldspring.beans.BeanFactory" required="true" />
<cfset variables.bf = bf />
</cffunction>

to your bean, and it will automatically have the BeandFactory injected in it. Obviously, you can store the BeanFactory in whatever variable you would like.

Chris



On Jun 21, 2007, at 2:07 PM, Jeff Chastain wrote:

Is it possible to inject the ColdSpring bean factory itself into an object?  I think I have seen this before, but I want to check and find out the proper syntax.

 

To head off the questions, I know the point of dependency injection is to inject any dependent objects into the parent object without the parent object knowing about factories etc.  However, in the case I am working on, the parent object does not know its dependencies before run-time.  In other words, the parent object has an API that can be programmatically used and in some cases will introduce new dependencies.  Therefore, I need the parent object to have the generic concept of a factory that it can use to load these dependent objects at run time.

 

Thanks

-- Jeff

 



Reply via email to