I recommend the first option, passing in the categoryDAO to your init
method. The main reason is this lessens your dependency on ColdSpring. In
the second example you are tying your CFC to the ColdSpring bean factory CFC
which sort of defeatst the purpose of inversion of control.
--Kurt
On 3/16/07, Nick Tong - http://TalkWebSolutions.co.uk <[EMAIL PROTECTED]>
wrote:
Hi list, i've just started playing with CS and so for so good. I''ve
got the following (constructor) code setup for a category method
(bean?):
<cffunction name="init" access="public" output="false">
<cfargument name="categoryDAO" type="model.categoryDAO"
required="yes"/>
<cfset variables.categoryDAO =
arguments.categoryDAO />
<cfreturn this />
</cffunction>
but i've seen the following, which seems to make more sense but i
can't figure out how to pass in the beanFactory
<cffunction name="init" access="public" output="false">
<cfargument name="serviceFactory"
type="coldspring.beans.BeanFactory" required="yes"/>
<cfset variables.checkUser =
arguments.serviceFactory.getBean('checkUser')/>
<cfreturn this />
</cffunction>
using this init method generate an error " The parameter
SERVICEFACTORY to function init is required but was not passed in.:" -
which makes sense?
XML:
<!-- category service -->
<bean id="categoryDAO" class="model.categoryDAO">
<constructor-arg
name="datasourcename"><value>${datasourceName}</value></constructor-arg>
</bean>
<bean id="categoryService" class="model.categoryService">
<constructor-arg name="categoryDAO">
<ref bean="categoryDAO"/>
</constructor-arg>
</bean>
What am i missing and which is better practice?
TIA
--
Nick Tong
web: http://talkwebsolutions.co.uk
blog: http://succor.co.uk
f..works: http://cfframeworks.com
short urls: http://wapurl.co.uk
green link: http://wapurl.co.uk/?4Z2YDLX
co.uk/?4Z2YDLX