ColdSpring bean creation magic…
Adam describes some fun and exciting changes in ModelGlue Unity. I can now ditch cflocation by using argument.event.forward(“location.cfm”).
Its just now that im loving ColdSpring, I think its much better to instantiate beans and set/create other objects using setters/getters through the property instead of constructor-arg. Here’s an example:
<cfcomponent displayname="UserService" output="false" hint="I am a UserService."> <cffunction name="init" access="Public" returntype="UserService" output="false" hint="I am a new UserService"> <cfreturn> </cfreturn> </cffunction><cffunction name="setUserGateway" returntype="void" access="public" output="false" hint="Dependency: UserService"> <cfargument name="userGateway" type="cfcodetrack.model.UserGateway" required="true"> <cfset variables.usergateway="arguments.userGateway"> </cfset> <cffunction name="getUserGateway" access="public" returntype="cfcodetrack.model.UserGateway" output="false"> <cfreturn> </cfreturn> </cffunction><cffunction name="authenticate" access="public" returntype="string" output="false"> <cfargument name="username" type="string" required="true"> </cfargument><cfargument name="password" type="string" required="true"> <cfdump var="#password#"> <cfabort> </cfabort> <cffunction name="getUsers" access="public" returntype="any" output="false"> <cfreturn> </cfreturn> </cffunction> </cfdump></cfargument></cffunction></cfargument></cffunction></cfcomponent> |
In your ColdSpring.xml your beans should only look like this:
<bean id="dsn" class="cfcodetrack.model.dsn"> <constructor -arg name="dsn"> <value>cfcodetrack</value> </constructor> </bean> <bean id="reactorFactory" class="reactor.reactorFactory"> <constructor -arg name="configuration"> <ref bean="reactorConfiguration"> </ref> </constructor> <!-- Security Service --> </bean><bean id="securityService" class="cfcodetrack.model.SecurityService" singleton="true"></bean> <bean id="userGateway" class="cfcodetrack.model.UserGateway" singleton="true"> <property name="reactorFactory"> <ref bean="reactorFactory"> </ref> </property><property name="dsn"> <ref bean="dsn"> </ref> </property> </bean><bean id="userService" class="cfcodetrack.model.UserService" singleton="true"> <property name="userGateway"> <ref bean="userGateway"> </ref> </property> </bean> |