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 I need to do here or is my understanding of what I am 
doing all wrong? If you were doing this how would you go about it, i learn best 
from examples (visual keys)

Thanks 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:324850
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to