Common.cfc has to be managed by ColdSpring for the dependency
injection to take place. I.e., you need:

<bean id="common" class="model.Common"> ... etc ... </bean>

And you need to get the "common" bean from ColdSpring wherever you use it.

Your XML has the bean named userGateway which doesn't seem right
(since you have a property injector method in Common.cfc for
userGateway)?

Sean

On Thu, Jul 23, 2009 at 5:28 AM, Glyn Jackson<glyn.jack...@newebia.co.uk> wrote:
>
> I am trying to get my head around ColdBox and ColdSpring (manly  ColdSpring) 
> so please be kind and any example code with comments would be much appreciate.
>
> My question
>
> I have a CFC called model/common.cfc
> This CFC contains all my SQL code that interacts with the database. However 
> in common.cfc I currently use the following code inside common.cfc on init() 
> to get my DNS details...
>
> <!-------- CONSTRUCTOR -------->
> <cfproperty name="dsn" type="coldbox:datasource:DBDetails" 
> scope="instance"><!---inject datasource--->
> <cfscript>
> instance = structnew();
> </cfscript>
> <cffunction name="init" access="public" returntype="any" output="false">
>  <cfargument name="dsn" type="any" _wireme="coldbox:datasource:DBDetails" />
>  <cfreturn this>
> </cffunction>
>
> I can then call it anywhere inside common like so #instance.dsn.getName()#
>
> Now this works fine, but wanting to expand my knowledge I have decided to 
> introduced ColdSpring (no experience of it before) I understand why I would 
> use an IOC so I wanted to start simple.
>
> I want to replace the above code and inject the DNS details into common.cfc 
> and use ‘one’ bean for all.
>
> I have followed the documentation on CB but am struggling mainly because of 
> my understanding I think. Here is what I have so far....
>
>
> I created my coldspring.xml (below) what I think it should do is inject DNS 
> into UserService.cfc this cfc is then called by common (userGateway). then in 
> my handler i can just called the one bean, right...
>
>
> coldspring.xml...
> <beans>
>        <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="userGateway" class="model.Common" />
>        <bean id="UserService" class="model.UserService">
>                <property name="dsnBean">
>                <ref bean="dsnBean" />
>                </property>
>                <property name="ConfigBean">
>                <ref bean="ConfigBean" />
>                </property>
>        </bean>
>
> </beans>
>
>
> I assumed this would allow me to access dns inside common.cfc but it does not.
>
> userservice.cfc
>
> <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>
>
>    <cffunction name="setDSNBean" access="public" returntype="void">
>     <cfargument name="DSNBean" type="Any" required="true"/>
>     <cfset variables.dsn = arguments.DSNBean.getName()>
>   </cffunction>
>
>     <cffunction name="setConfigBean" access="public" returntype="void">
>      <cfargument name="configBean" type="Any" required="true"/>
>     <!--- <cfset variables.mailName = 
> arguments.configBean.getKey("mailUsername")>--->
>    </cffunction>
>
>
> </cfcomponent>
>
> I dont know what to do in common.cfc to pull it...
>
> any help/examples on what

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:324879
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to