The more I work in ColdBox the more I want to learn, so pardon my ramblings but yesterday ColdBox and ColdSpring took my fancy. I have never worked with ColdSpring nor any other AOP for CFC's.
So ColdSpring, what's all that about then? To be honest I am still not sure why I would use it. I started by playing around, I wanted to inject my ColdBox DNS setting into my common.cfc (database gateway).
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<beans default-autowire="byName">
<bean id="coldboxFactory" class="coldbox.system.extras.ColdboxFactory" />
<bean id="ConfigBean" factory-bean="ColdboxFactory" factory-method="getConfigBean" />
<bean id="dsnBean" factory-bean="ColdboxFactory" factory-method="getDatasource">
<constructor-arg name="alias">
<value>DBDetails</value>
</constructor-arg>
</bean>
<bean id="userService" class="model.UserService" />
<bean id="userGateway" class="model.common" >
<property name="dsnBean">
<ref bean="dsnBean" />
</property>
</bean>
</beans>1 <beans default-autowire="byName">
2 <bean id="coldboxFactory" class="coldbox.system.extras.ColdboxFactory" />
3 <bean id="ConfigBean" factory-bean="ColdboxFactory" factory-method="getConfigBean" />
4 <bean id="dsnBean" factory-bean="ColdboxFactory" factory-method="getDatasource">
5 <constructor-arg name="alias">
6 <value>DBDetails</value>
7 </constructor-arg>
8 </bean>
9 <bean id="userService" class="model.UserService" />
10
11 <bean id="userGateway" class="model.common" >
12 <property name="dsnBean">
13 <ref bean="dsnBean" />
14 </property>
15 </bean>
16
17 </beans>
I then created a UserService.cfc. The idea I think behind this is that I access the userService.cfc to get to common.cfc (gateway) and common.cfc gets the DNS setting injected.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfcomponent name="User Service">
<cffunction name="init" access="public" returntype="any" hint="Constructor.">
<cfreturn this />
</cffunction>
<cffunction name="getUserGateway" access="public" returntype="any" output="false" hint="Return the UserGateway.">
<cfreturn variables.instance['userGateway'] />
</cffunction>
<cffunction name="setUserGateway" access="public" returntype="void" output="false" hint="Set the UserGateway.">
<cfargument name="userGateway" type="any" required="true" hint="UserGateway" />
<cfset variables.instance['userGateway'] = arguments.userGateway />
</cffunction>
</cfcomponent>
1 <cfcomponent name="User Service">
2
3 <cffunction name="init" access="public" returntype="any" hint="Constructor.">
4 <cfreturn this />
5 </cffunction>
6
7 <cffunction name="getUserGateway" access="public" returntype="any" output="false" hint="Return the UserGateway.">
8 <cfreturn variables.instance['userGateway'] />
9 </cffunction>
10
11 <cffunction name="setUserGateway" access="public" returntype="void" output="false" hint="Set the UserGateway.">
12 <cfargument name="userGateway" type="any" required="true" hint="UserGateway" />
13 <cfset variables.instance['userGateway'] = arguments.userGateway />
14 </cffunction>
15 </cfcomponent>
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
common.cfc
<cffunction name="setdsnBean" access="public" returntype="void" output="false" hint="Set the dsnBean.">
<cfargument name="dsnBean" type="any" required="true" hint="dsnBean" />
<cfset variables.instance['dsnBean'] = arguments.dsnBean />
</cffunction>1 common.cfc
2 <cffunction name="setdsnBean" access="public" returntype="void" output="false" hint="Set the dsnBean.">
3 <cfargument name="dsnBean" type="any" required="true" hint="dsnBean" />
4 <cfset variables.instance['dsnBean'] = arguments.dsnBean />
5 </cffunction>
Why is this any better? I could have achieved this all in the init() method without ColdSpring, or I could have extended my CFC, or I could have even created a config CFC and injected that into the common.cfc.
Sorry, If these questions are just ignorant.
ColdBox - SagePay VSP Driect Plugin
ZAC said: i like this, ive been looking for some help with this integration so i found this just at the right ... [More]