In our Beans.xml we need to reference the properties structure by the key. Code for Beans.xml
Now that we have our beans.xml reading dynamic variable how can we pass this to the default ColdSpring.xml that Model Glue uses?First off when it comes to Model Glue there is already ColdSpring.xml which holds all the config imformation for the application, ORM etc etc. We're not going to touch that so this method is something you can introduce midway through a project. What we are going to do is introduce Beans.xml as the Parent Bean Factory to the child ColdSpring.xml.Create a SimpleConfig bean from Model Glue (ModelGlue.Bean.CommonBeans.SimpleConfig) and save this in the Beans.xml file. This config bean will hold details for our email server. The values are going to come from the Application scope.You xml file should look like:
In the Appliacation.cfm add the following code
At this point we have our bean factory stored in application.beanFactory2. We are going to reference this in the index.cfm of MG under the HIERARCHIAL BEAN FACTORY SUPPORT area. Look for the commented out <cfset> which sets the variable ModelGlue_PARENT_BEAN_FACTORY. Uncomment the <cfset> and add the following:
At this point the hard work is done. All that is left is to add a bean that uses the config setting. In my case I have a CFC in a Model folder which accepts the constructor argument "EmailConfig" e.g.
Thats it. From your emailCFC you just need to reference variables.emailConfig.getconfigSetting('emailServer') to the get the server etc.This post couldn't of been done without the help of http://www.danvega.org/blog/index.cfm/2006/11/25/Passing-Properties-To-ColdSpring and http://groups.google.com/group/model-glue/browse_thread/thread/de628a4fb85c6ebd/ so for futher investigation you can start there.