To get started with LightWire download the LightWire.cfc and the sample LightWireConfig.cfm from the SVN repository. You can place either file anywhere you want. I personally put the cfc in .com.lib (my library directory) and the config file in a "config" directory both of which are below my web root for a given project, but you can put the files anywhere you want.
Somewhere in your Application.cfc (in the onApplicationStart method) you’ll want to set the path to the LightWire config file path and then createobject LightWire. I currently just create it in application scope. Below is the config code I use which happens to use an application.CFMapping for the application specific mapping.
<cfset Application.LightWire = CreateObject("component","#application.CFMapping#.com.lib.LightWire").Init(Local.ConfigFilePath)>
You will want to customize the config file. See my recent posting on the syntax for that.
That is just about it. If you want to create an object (transient or singleton), just call LightWire and it will return the fully loaded object. Below are a couple of sample requests. If you want a singleton, use getSingleton(). If you want a transient, getTransient(). All you need to pass in is the name of the class you want to instantiate.
<cfset Request.PageService = Request.LightWire.getSingleton("PageService")>
<!--- Create PageObject --->
<cfset Request.PageObject = Request.LightWire.getTransient("PageObject")>
I could have created a single get() method as it would be easy to tell from the config file whether it was a singleton or a transient, but I decided I’d rather have a really explicit interface which would make it very obvious in my code what I was doing. Please also bear in mind that most objects will just be direct injected, so a lot of things like PageService and PageDAO won’t ever be explicitly called – they’ll just be injected into the appropriate controller cfcs so in practice you only need to call LightWire occasionally (pretty much wherever you'd have called ColdSpring plus wherever you'd have called your custom bean factories if you need DI into the beans).
If you are new to DI/IoC, start off by downloading ColdSpring. It has better documentation, more support and many more people using it. LightWire is for people who have explored ColdSpring and have decided they’d like an approach more optimized for DI into transient objects and/or because they like programmatic config files.
Any comments/thoughts much appreciated!