Sean and everyone,

Sorry it took me so long to respond. I was on my honeymoon in St. Lucia. Since I late responding I am going to make up by writing a longer response. :)

First off both the ApplicationContext and hierarchical bean factory are modeled directly off of Java's Spring framework.

http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#context-introduction
http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#beans-factory

ApplicationContext implments the BeanFactory interface with the addition of a couple of methods which can be used to set a parent AppContext. The applicationContext simple delegates to the local bean factory and then to the parent bean factory if necessary. The idea is that you can have separate AppContexts with different parts of your application and then tie them together in a hierarchical manner. Currently I don't have a need for the hierarchical AppContext in my applications but I can see the day where with all the different services/managers I am building I may need to modularize them further. The example the Spring's documentation cites is that you might want to use it to help in the "loading of multiple (hierarchical) contexts, allowing each to be focused on one particular layer, for example the web layer of an application". In all the Java Spring applications I have worked with I have always interacted with an instance of ApplicationContext rather then with a BeanFactory itself.

The hierarchical bean factory is something I specifically needed for the project I am working on. In my project I have a need to setup a set of enterprise wide services for managing things like people, organizations, products, orders, ect. Then each application (which has its own set of services, and thus its own local bean factory) may depend on this these enterprise wide services. Essentially I need a way to have the enterprise services act as a separate module in ColdSpring that can have it own xml config file. Then my app specific services need to be able to have dependencies to services in this bean factory (which becomes the parent bean factory) which contains the enterprise wide services.

In my application.cfm I create the parent bean factory first and then I have the Mach II plugin pull that bean factory out of the DefaultApplicationContext I stored in application.baseServicefactory. So the bean factory for the application gets it parent bean factory set to the one I initialized in my application.cfm which would contain my enterprise wide services.

Application.cfm at root of site 1:

<!--- Create bean factory for the enterprise wide services --->
<cfset beanFactory = createObject("component", "coldspring.beans.DefaultXMLBeanFactory").init(
       structNew(), defaultProperties)>
<cfset beanFactory.loadBeans(ExpandPath("config/services2.xml"))>

<!--- Create applicationContext for the enterprise wide services --->
<cfset application.baseServiceFactory =
       createObject("component", "coldspring.context.DefaultApplicationContext").init(beanFactory)>

Mach II config file for an application that needs the enterprise services as the parent in its local bean factory:

<plugin name="coldSpringPlugin" type=" coldspring.machii.coldspringPlugin">
 <parameters>
  <parameter name="beanFactoryPropertyName"  
value="serviceFactory" />

  <parameter name="configFilePropertyName" value="servicesConfigFile" />
  <parameter name="configFilePathIsRelative" value="true" />
  <parameter name="resolveMachiiDependencies" value="true" />
  <parameter name="placeFactoryInApplicationScope" value="true" />
  <parameter name="parentBeanFactoryKey" value="baseServiceFactory" />
 </parameters>
</plugin>

I will try to post this to my blog too along with more an explanation of how my services are structured. Hopefully more people in the CF community can build better OO applications by utilizing ColdSpring and solid OO models with services/managers, DAOs, and getways. Hopefully people find this explanation helpful. An example application with this structure might also be helpful.

--Kurt

On 11/17/05, Sean Corfield <[EMAIL PROTECTED]> wrote:
> On 11/17/05, Kurt Wiersma <[EMAIL PROTECTED] > wrote:
> > I worked on the new ApplicationContext and hierarchical bean factory
> > support. I will try to put together some documentation on how to use
> > it soon. I should also probably explain how the new flash remoting
> > support works as well. :)
>
> Could you provide even a one sentence summary here of how those new
> features work?
>
> (and thanx for all your work on ColdSpring - it's awesome!)
> --
> Sean A Corfield -- http://corfield.org/
> Got frameworks?
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>

Reply via email to