I'm using the current 2.6.2 release of Coldbox and trying to learn to
use Coldspring with it for dependency injection. I'm perhaps confused
though on how that is supposed to happen within the Coldbox framework.
For the purposes of learning, I'm just setting up a very simple dao
and service. estatement will be a dao and it needs to know the
datasource for its operations. estatementService is the service layer
that will act as an api to estatement. In my coldspring config file I
have this:
<bean id="estatement" class="model.estatement.estatement">
<constructor-arg
name="dsn"><value>${datasources.dsn.name}</value></constructor-arg>
</bean>
<bean id="estatementService"
class="model.estatement.estatementService" singleton="false">
<constructor-arg name="estatement" >
<ref bean="estatement"/>
</constructor-arg>
</bean>
This would seem to indicate to me that estatementService depends on
estatement and that estatement needs to know the value of dsn which is
${datasources.dsn.name} which is a variable from my Coldbox config.
<Datasources>
<Datasource alias="dsn" name="notification" dbtype="mssql"
username="" password="" />
</Datasources>
Now in my handler, I can invoke the estatementService like thus:
var oService = getPlugin("ioc").getBean("estatementService");
That works fine, if I stick it in the rc scope and dump it in my view,
I see that it exists and has methods and other yummy stuff. But then I
try to use it to create an estatement thusly:
rc.oService = oService;
rc.estatement = rc.oService.createstatement();
And I get an error saying that the DSN parameter of the init function
needs to be passed in but hasn't been.
In estatementService all I'm doing is this:
<cffunction name="createstatement" access="public" output="false"
returntype="model.estatement.estatement">
<cfset var estatement =
createObject("component","model.estatement.estatement").init(argumentCollection=arguments)
/>
<cfreturn estatement />
</cffunction>
And in the estatement cfc the init function is bare bones:
<cffunction name="init" access="public" output="false"
returntype="model.estatement.estatement">
<cfargument name="dsn" type="string" required="true">
<cfset variables.dsn = arguments.dsn>
<cfreturn this>
</cffunction>
It was my understanding that when I used the IOC plugin to get the
estatementService that it would see that it needs the estatement bean
which would therefore grab the dsn value and inject it into my class.
So why doesn't the estatement.cfc init function know about dsn from
Coldspring? I think I'm missing something fundamental and easy.
Thanks,
Judah