ColdSpring and Dependency Injection for the beginner part 2: Constructor Injection.

Time to code! woohoo! I am going to carry on with the components from the last post which are userService and userDAO in a "model" directory on the root. For this post we'll assume that my DAO only has basic CRUD methods; Create, Read, Update, and Delete

I am going to demonstrate the Constructor Injection method of dependency injection which was summarised quickly in my last post. I think a recap is need here:

<constructor-arg name="argumentName"/>
This tag will cause Coldspring to supply your bean with a value or object reference when it is instantiated (during a CFC's init() method), passed as an argument named via the name attribute.

What the above statement means in basic terms is that the userService must have an init() method which accepts the userDAO object as an argument and sets it to a variable. e.g.

Posted: 24-Nov-2006

View: 5725

Permalink: here

Comments

keep this up Andy, I think the value of ColdSpring is finally starting to sink even with just the two entries you have wrote on this.

Cheers min.

#1 dc
24/Nov/06 2:50 PM

Andy - something has just gone 'click' - I have a mental dependancy problem trying to understand coldspring! On the one hand, I think I need to understand it all at once, but don't have all the information at hand. On the other hand, there's way too much to try to understand at once!
I think this series is helping, but I won't know for sure until later...

#2 Antony
27/Nov/06 12:02 AM

Anthony, I've got one more part in this series which just covers the setter injection method, then thats it for now. Depending on time I am going to try and get that done for the begining of the coming week, so look out!

#3 Andy J
27/Nov/06 12:09 AM

Hi Andy, Nice write up, i've added this series to the articles section on http://cfFrameworks.com, I hope you don't mind: http://cfframeworks.com/index.cfm?fuseaction=app.a...

Also in you somFunction method, to make thing a bit clearer could you put
<cfset var userDao = variables.userDAO.getuserDAO() /> ?

#4 Nick Tong
15/Mar/07 10:49 AM