| Before we all get too crazy trying to figure out how to have an object become auto wired with the bean factory, ColdSpring already provides a ServiceLocator type utility to manage the location of the bean factory for you, in a provided scope. So lets say you want to place a bean factory in application scope, you can use the utility's default location like this: <!--- create the utils cfc and the bean factory ---> <cfset var bfUtils = createObject("component","coldspring.beans.util.BeanFactoryUtils").init()/> <cfset var bf = createObject("component","coldspring.beans.DefaultXmlBeanFactory").init()/> <!--- load your beans ---> <cfset bf.loadBeansFromXmlFile([configFile.xml])/> <!--- ok now put bean factory in a default location ---> <cfset bfUtils.setDefaultFactory('application', bf) /> <!--- OR, put in a named location ---> <cfset bfUtils.setNamedFactory('application', 'myFactory', bf) /> So now we can use the same component from inside any cfc. Like so, maybe in an init method: <cfset var bfUtils = createObject("component","coldspring.beans.util.BeanFactoryUtils").init()/> <cfset var bf = bfUtils.getDefaultFactory('application') /> <!--- OR ---> <cfset var bf = bfUtils.getNamedFactory('application', 'myFactory') /> Now you can get your bean factory from anywhere. The mach-ii plugin already uses the BeanFactoryUtils cfc and uses the key 'beanFactoryPropertyName', defined as a parameter to the plugin, but if it doesn't exist, it uses the default location. I spoke to Joe about using the same system in ModelGlue, so it should be consistent there too. Spring for Java has the same mechanism, and it is used in the SpringContextLoaded (Servlet or Listener, sorry the actual class name is not quite that). So in Spring for Java, the 'standard' way to locate beans in a web app is by accessing the factory through the utility. I think overall, I would like to see an approach like this favored over trying to hack a system for injecting the bean factory into objects, because it is just a lot simpler and more flexible. Plus it opens up ColdSpring managed beans to be shared across not only application instances, but different types of applications as well. A good example being a remote interface for a mg/m2 app. OK, hope that can help! Chris On Mar 9, 2006, at 7:09 PM, Paul Roe wrote: You guys are awsome, and like I was saying I won't go about putting this practice into production, it's just how I like to learn. I go down a path untill I find the end then start another. The info that Sean gave me will definetly give me something to explore and in the process learn a lot about coldsprings capabilities. |
- [coldspring-dev] help Paul Roe
- [coldspring-dev] help Dave Ross
- [coldspring-dev] help Adam Crump
- [coldspring-dev] help Peter J. Farrell
- [coldspring-dev] help Paul Roe
- [coldspring-dev] help Peter J. Farrell
- [coldspring-dev] help Sean Corfield
- [coldspring-dev] help Dave Ross
- [coldspring-dev] help Jared Rypka-Hauer
- [coldspring-dev] help Paul Roe
- [coldspring-dev] help Chris Scott
- [coldspring-dev] help Sean Corfield
- [coldspring-dev] help Chris Scott
- [coldspring-dev] help Chris Scott
- [coldspring-dev] help Baz
- [coldspring-dev] help Dave Ross
