Passing the BeanFactory into your beans is "bad", because you're no
longer doing dependency injection, you're just using a global factory.
To put that another way, you're throwing away the primary benefit of
ColdSpring.  There are some cases where you do have to inject a bean
with the bean factory (using the BeanFactoryAware property, not a
constructor argument), but double check before you do it, as it's
likely indicative of some underlying architectural issue.

In short, ColdSpring managed beans should almost never get anything on
their own, everything they need should be provided to them by
ColdSpring except in certain edge cases.  So your first CFML snippet
and the last XML snippet are the "best practices" way to do it, the
middle snippet works, but isn't the best way to approach it.  The
'checkUser' bean should be wired in as a constructor argument
directly.

cheers,
barneyb

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




--
Barney Boisvert
[EMAIL PROTECTED]
http://www.barneyb.com/

Got Gmail? I have 100 invites.
e 100 invites.

Reply via email to