Passing Application scoped variables to ColdSpring within Model Glue

Passing defaultProperties in ColdSpring with Model GlueOr Using defaultProperties with CS and MG. I couldn't figure out which title would be better.Basically this is a guide on how to pass variables into ColdSpring. In my case from the Application scope. Recently I've been working on a Model Glue, Transfer, and ColdSpring app and came across a problem which I couldn't find a direct answer to online. The application I'm working is only a small part of the site and has some settings in the Application scope which needs to remain there. Usually I put all my variables in a ColdSpring/Model Glue simpleConfig Bean (using the class ModelGlue.Bean.CommonBeans.SimpleConfig) but this time I needed CS to get the variables from the application scope. This actually isn't too hard as you can pass properties(dynamic variables) into the config.xml e.g.Here's the code for creating the bean factory. You would find this in onApplicationStart or at the top of your Application.cfm.Code for Application.cfm/cfc In our Beans.xml we need to reference the properties structure by the key. Code for Beans.xml ${dsn} 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: ${emailServer} ${emailUName} ${emailPWord} 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 and so for futher investigation you can start there.
comments powered by Disqus