Often, your application will need to know some configuration information, such as datasource names or mailservers. For the sake of example, let's pretend that your application needs to use the <cfmail> tag, and you'd like to be able to store the servername, username, and password settings in a file outside of your source code. That's just good practice.
In Model-Glue:Unity, it's also really easy.
Every Model-Glue:Unity application (that's not an upgrade from 1.x) has a ColdSpring.xml that's intended to serve as the central store of all configuration information for your application.
The file is organized into a series of <bean> tags. Each bean represents a CFC that you can ask for inside of your Model-Glue application. Full use of ColdSpring is beyond the scope of this document - it's capable of a lot more than we're about to cover.
Model-Glue:Unity comes with a bean (ModelGlue.Bean.CommonBeans.SimpleConfig) that's well suited for common configuration chores. It has a single property (config) that is a structure set through the setConfig() function. This structure serves as a "registry" of configuration settings. Each setting can be requested through the bean's getConfigSetting() function by passing the name of the setting to retrieve.
To apply this to the scenario of a mail server, we could add the following to ColdSpring.xml:
<bean id="mailConfiguration" class="ModelGlue.Bean.CommonBeans.SimpleConfig">
<property name="config">
<!-- In Coldspring, a "map" represents a struct -->
<map>
<entry key="mailserver">
<value>mail.mydomain.com</value>
</entry>
<entry key="username">
<value>smtpUsername</value>
</entry>
<entry key="password">
<value>smtpPassword</value>
</entry>
</map>
</property>
</bean>
After the configuration XML is added to ColdSpring, using the configuration settings is easy. Below is an example listener function that uses the configuration settings in a <cfmail> tag:
<cffunction name="sendEmail" access="public" returnType="void" output="false">
<cfargument name="event" type="any">
<cfset var message = arguments.event.getValue("message") />
<cfset var subj = arguments.event.getValue("subj") />
<cfset var to = arguments.event.getValue("to") />
<!--- Get mail configuration --->
<cfset var mailCfg = getModelGlue().getBean("mailConfiguration") />
<!--- Use the mail configuration to send mail --->
<cfmail
to="#to#"
subject="#subject#"
server="#mailCfg.getConfigSetting("mailserver")#"
username="#mailCfg.getConfigSetting("username")#"
password="#mailCfg.getConfigSetting("password")#"
>#message#</cfmail>
</cffunction>