injection with coldspring question

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">
  <bean id="estatementService"
class="model.estatement.estatementService" singleton="false">
    <constructor-arg name="estatement" >
      <ref bean="estatement"/>

This would seem to indicate to me that estatementService depends on
estatement and that estatement needs to know the value of dsn which is
${} which is a variable from my Coldbox config.

    <Datasource alias="dsn" name="notification" dbtype="mssql"
username="" password="" />

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"
  <cfset var estatement =
  <cfreturn estatement />

And in the estatement cfc the init function is bare bones:
<cffunction name="init" access="public" output="false"
  <cfargument name="dsn" type="string" required="true">
  <cfset variables.dsn = arguments.dsn>
  <cfreturn this>

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.



I recommend trying the new model features first:

If you think you need more than what ColdBox can offer in terms of DI, then upgrade to CS or LW. We believe the new model features would be more than sufficient to meet your needs.


Ah, very nice. I'll have to look at it more extensively later but that
looks like what I need. I don't need a lot of features from an AOP
framework right now, I'm just trying to get my head around the very
basics and then I'll add more later. Same goes with an ORM. I think
I'll like Transfer a great deal but I'm not yet ready to implement it,
I want to learn one major framework at a time.


Understandable Judah. I think the model features would be an easy transition into using dependency injection and getting you used to the idea of objects and relationships. Using an ORM would be the next step and for that, you really need to sharpen your OO skills first. But, step by step.


i'm still curious why his stuff didn't work. on initial glance
everything looked in order. no?


Well, it does not work, because coldspring is not creating your
estatement, but your service is. So nothing is getting wired:
rc.estatement = rc.oService.createstatement();

If you want your service to create your objects for you, then you must
set its dependencies yourself. Or you can also inject the coldspring
bean factory into the service and use it to build your objects from


Is that not what I was doing with this statement: var oService =

That should, in my thought process, load the service through
coldspring which should do all the dependencies, no?

Yes, that part is correct.

The part where you create the estatement via the service is what causes the problem because the service is now in charge of creating the objects and not coldspring.

Out of curiosity, how would you go about it then using Coldspring? I
was basing the code I wrote off of a set of handlers/service/dao/bean
that was generated by the coldbox template for illudium and I thought
I understood what they are doing.