Getting started with ColdSpring and autowire

Submitted by Falken on

This brief article is a follow up to the code that nearly worked at the end of Mark Drew's Scotch on the Rocks '07 presentation on ColdSpring.

The idea is that if you've written lots of setFoo() methods, so you can have property tags in your ColdSpring config inject dependencies at run-time, it rapidly seems as though you are writing everything twice (once in the CFC, once in the XML).

What autowire, and specifically 'byName' autowire do is look for all the setFoo() methods in a bean, and then, if there is another bean called 'foo', it will call setFoo() with an instance of the foo bean.

The attached code is a version of Mark's 'mailer' example, rewritten to take advantage of autowire. Just unzip it into a ColdFusion server's web root and it should run.

The output isn't very exciting, but what has happened behind the scenes is that the 'mailer' object has been given the 'config' object (containing the mail server name) simply by having a public setConfig() method.

Funky, eh ?

Sections
Attachment Size
coldspring_autowire_demo.zip71.25 KB 71.25 KB