coldspring

Ketan Jetty
enthusiasm for technology

coldspring

ColdSpring is an inversion-of-control framework/container for CFCs (ColdFusion Components). Inversion of Control, or IoC, is synonymous with Dependency Injection, or DI. A dependency is when one piece of a program depends on another to get its job done.

The following section will provide you 2 code formats, one 'app-normal' showing the standard way of doing coldfusion program and the other 'app-cs' which shows code using coldspring framework.


   app-normal code                         app-cs code

The following will walk you thru the process of converting your normal coldfusion code to coldspring framewok. I have highlighted the code differences. For more information on coldspring, please go to coldspringframework.org

cs.xml [coldspring configuration xml file]
app-normal :: no configuration file

			
app-cs :: cs.xml, coldspring configuration file
<?xml version="1.0" encoding="UTF-8"?>
<beans>
	<bean id="abstractDAO" class="app-cs.model.abstractDAO">
        <constructor-arg name="dsn">
            <value>dsnKJdev</value>
        </constructor-arg>
    </bean>

    <bean id="typesService" class="app-cs.model.types.typesService">
        <property name="typesDAO">
            <ref bean="typesDAO"/>
        </property>    
    </bean>

    <bean id="typesDAO" class="app-cs.model.types.typesDAO" parent="abstractDAO" />
</beans>

application.cfc
app-normal :: application.cfc
<cffunction name="onApplicationStart" returnType="boolean" output="true">
	<cfset StructClear(application) />
	<cfset application['env'] = createObject("component","config").getConfig() />	
	
	
	<cfreturn true />
</cffunction>
app-cs :: application.cfc [lines 4,5]
<cffunction name="onApplicationStart" returnType="boolean" output="true">
	<cfset StructClear(application) />
	<cfset application['env'] = createObject("component","config").getConfig() />	
	<cfset application.cs = createObject("component","coldspring.beans.DefaultXmlBeanFactory").init() />
	<cfset application.cs.loadBeans(expandPath("cs.xml"))/>
	<cfreturn true />
</cffunction>

model.abstractDAO.cfc
app-normal :: abstractDAO.cfc
<cffunction name="init" access="public" returntype="abstractDAO" hint="constructor">
	
	<cfset setDsn(application.env.dsn) />
	<cfreturn this />
</cffunction>
app-cs :: abstractDAO.cfc [line 2,3]
<cffunction name="init" access="public" returntype="abstractDAO" hint="constructor">
	<cfargument name="dsn" type="string" required="true"/>
	<cfset setDsn(arguments.dsn) />
	<cfreturn this />
</cffunction>

model.types.typesService.cfc
app-normal :: typesService.cfc [line 2]
<cffunction name="init" access="public" returntype="typesService">
	<cfset setTypesDAO(CreateObject("component","app-normal.model.types.typesDAO").init()) />
	<cfreturn this />
</cffunction>
app-cs :: typesService.cfc
<cffunction name="init" access="public" returntype="typesService">
	
	<cfreturn this />
</cffunction>

model.types.typesDAO.cfc
app-normal :: typesDAO.cfc
<cffunction name="init" access="public" returntype="typesDAO" hint="constructor">
	
	<cfset super.init() />
	<cfreturn this />
</cffunction>
app-cs :: typesDAO.cfc [line 2,3]
<cffunction name="init" access="public" returntype="typesDAO" hint="constructor">
	<cfargument name="dsn" type="string" required="true"/>
	<cfset super.init(arguments.dsn) />
	<cfreturn this />
</cffunction>

coldfusion


CF Quick Reference


Ginger CMS
the future of cms, a simple, easy and intutive content management system ... more


CFTurbine
cf prototyping engine, generates boilerplate code and ... more


Jrun monitor
monitor and timely auto-restart to avoid Jrun hang ... more


Inheritance Config.
uses OOPs inheritance to create configuration file ... more


Real Estate App.
complete real estate application using data from MLS ... more


Search Engine Lite
create your own search engine for your web site ... more