I was reading through one of Sean Corfield's blog posts about using the TDOBeanInjectorObserver to inject a service into a transfer object and wondered how i might do this with reactor. Here is his post
http://blog.broadchoice.com/index.cfm/2008/8/15/Better-Living-Through-Transfer-and-ColdSpring
Anyway, after a bit of fiddling i think I've managed it using a bit of AOP, which tbh had always been a slight mystery to me, and probably still is!
I though i'd share this to see if anyone else is using anything like this, or incase someone sticks there hand up and says uhhmm no.. dont do that!
Here's what I've cobbled together.
Coldspring.xml<beans default-autowire="byName">
<bean id="reactorConfiguration" class="reactor.config.config">
all the usual stuff here ...
</bean>
<bean id="reactorFactoryTarget" class="reactor.reactorFactory">
<constructor-arg name="configuration">
<ref bean="reactorConfiguration" />
</constructor-arg>
</bean>
<bean id="reactorFactory" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="reactorFactoryTarget" />
</property>
<property name="interceptorNames">
<list>
<value>beanInjectorAdvisor</value>
</list>
</property>
</bean>
<bean id="beanInjector" class="coldspring.utils.BeanInjector">
<constructor-arg name="debugMode"><value>false</value></constructor-arg>
</bean>
<bean id="beanInjectorAdvice" class="model.aspects.BeanInjectorAdvice" />
<bean id="beanInjectorAdvisor" class="coldspring.aop.support.NamedMethodPointcutAdvisor">
<property name="advice">
<ref bean="beanInjectorAdvice" />
</property>
<property name="mappedNames">
<value>createRecord</value>
</property>
</bean>
<bean id="EncryptionService" class="model.service.EncryptionService" />
</beans>
model/aspects/BeanInjectorAdvice.cfc<cfcomponent name="BeanInjectorAdvice" extends="coldspring.aop.MethodInterceptor">
<cffunction name="setBeanInjector" returntype="void" access="public" output="false">
<cfargument name="beanInjector" type="any" required="true"/>
<cfset variables.beanInjector = arguments.beanInjector />
</cffunction>
<cffunction name="invokeMethod" access="public" returntype="any">
<cfargument name="methodInvocation" type="coldspring.aop.MethodInvocation" required="false" />
<cfset var rtn = arguments.methodInvocation.proceed() />
<cfset variables.beanInjector.autowire(rtn) />
<cfreturn rtn />
</cffunction>
</cfcomponent>
model/data/Record/UserRecord.cfc contains
<cffunction name="setEncryptionService" access="public" output="false" returntype="void">
<cfargument name="EncryptionService" />
<cfset variables.beans.encryptionservice = arguments.encryptionservice />
</cffunction>
so in my limited test (ie, press F5 - no error message) it seems to work... which is nice.
Chris