By Peter Bell

LightWire or ColdSpring?

So, someone finally asked on cfcdev: "Any thoughts or opinions on the differences between Lightwire and ColdSpring?".

Below is my response. Any clarifications or refinements appreciated. Flames tolerated, but it'd be nice if we could have a logical, balanced, framework comparison between grown ups - just this once.

In particular, any additional benefits of ColdSpring that I've missed, I'd appreciate if you could add in the comments.

Well, I just posted a couple of entries:

http://www.pbell.com/index.cfm/2007/4/5/LightWire-The-Benefits-of-a-Programmable-Configuration-Object

http://www.pbell.com/index.cfm/2007/4/5/LightWire-Why-I-Love-Mixin-Injections

Here are some thoughts: ColdSpring is much more widely used. It has been out there longer. It has better documentation. It is solid, works well and there are a good community of users. It is also the only game in town (at the moment) if you want AOP or automagic remote bean proxies.

Two minor LW considerations:

LightWire is smaller (two files) so if you happen to want to drop it into a project, you don’t need to add a mapping and a whole other dependency – you just add two files plus your config.

LightWire is simpler – if you want to know HOW a DI engine works, the core code in LightWire is under 400 lines so it is a great way to look under the hood and really get the pattern.

Three bigger ones:
1. DI Into Transients: LightWire is OPTIMIZED for DI into transients as well as singletons. You CAN DI into transients using ColdSpring, but every time I asked, I was told it was not recommended. So if you want to do a lot of User.save() where you put UserDAO within the User object, at least look at LightWire as that is what it was build for.

2. Programmatic Config: LightWire uses a programmatic config. Programmatic configs vs. XML is pretty much a religious war. All I will say is that there are clearly benefits to both approaches depending on your use cases (there are seldom wars between a smart approach and a consistently useless and stupid one) so if you want a programmatic config file, feel free to check out LightWire.
3. Mixin injection: See the second link above, but basically this is a third type of DI in addition to constructor and setter injection (which LightWire also supports). In my opinion it allows for the benefit of setter injection (handling circular dependencies) without having to add a bunch of setter methods to your classes just to make your DI work. I love the approach, but it is not a widespread solution (I haven’t noticed it in any other DI frameworks in any languages, although I may have missed it).

Please also note that unlike ColdSpring, LightWire does not support auto-wiring. I’d rather have a single definitive config file and use mixin injection to cut down on all of the spurious setter methods, but if you like auto-wiring, you won’t see it in LightWire – now or in the future.

I would recommend if you are interested in DI into transients, programmatic config or mixin injection you should check out LightWire. Otherwise, unless the small size or the learning benefits are of interest, I’d say ColdSpring is still the default choice.

Best Wishes, Peter

Comments
'it'd be nice if we could have a logical, balanced, framework comparison between grown ups - just this once.'

You are the eternal optomist!
# Posted By Scott Stroz | 4/5/07 2:15 PM
(Peter, we have talked about this, but I thought I would post here) The difference between then is that ColdSpring is configured with an XML file.

Now, a lot of people ask what is the use when you can just as easily write the config in CF (or any other language) since it isn't compiled. The main point of using an XML file in any framework is not so that *YOU* the developer can change it (or for it to be a pain in the A** because it is a bulky format) but so that any other tool can edit it.

You can parse all the XML's of various apps and know what you are talking about (I am looking at you Struts, and Spring too!) by having a standard way to parse any configuration file.


Just my 2 british pence
# Posted By Mark Drew | 4/5/07 2:24 PM
Hi Mark,

Good point. There are MANY benefits of XML files - just search my blog for XML and you'll find a bunch of posts praising the benefits of the technology. I still find programmatic config files to better meet my use cases and I just like them more, but there are loads of good reasons to use XML and it is worth learning about all of them before you decide to go off and do something else.
# Posted By Peter Bell | 4/5/07 2:29 PM
@Scott - That's me!
# Posted By Peter Bell | 4/5/07 2:32 PM
Oh, just for the record - you COULD configure LW using XML. Someone just needs to write a short method to read (say) a CS XML file and use it to generically call the right config methods. I wrote the API with that in mind, so it'd be easy to do if anyone wanted to use XML with LW.
# Posted By Peter Bell | 4/5/07 2:49 PM
I think programmer buy-in has a lot to do with it. I tend to have the attention of a Java developer when I say that ColdSpring is based upon Spring. They usually stop and pay a bit of attention.
# Posted By dc | 4/5/07 5:20 PM
True. But when I speak to a non-Java programmer and tell them I offer programmatic configuration rather than having to use XML, they usually take notice. Same buy in - different set of programmers :->
# Posted By Peter Bell | 4/8/07 4:52 PM
OK, here is my question. Can I put the core "lightwire" files anywhere on my server that is accessable? (Meaning... do I have to create a CFMapping?) That is the one thing I hate about custom solutions. It is BAD form when solutions that are meant to integrate don't flex appropriately. (That is why some of the solutions out there are using the concept of storing themselves in COM/NET/ORG directories. I also have an alternative where all the libraries go into a "share" folder, nested by type and/or library.)
# Posted By John Farrar | 4/30/07 12:08 PM
Hi John,

You can put LightWire anywhere and you can put your LightBeanConfig file anywhere also (and they can be two different anywheres). You'll have to fix the "extends" path in your config file, and you'll have to know and use the right paths to instantiate your config bean and the framework, but it is designed to be easy to place anywhere. I personally don't put LightWire under a LightWire mapping but have it as a subdirectory under my main framework mapping, so I know it works.
# Posted By Peter Bell | 4/30/07 12:17 PM
Hoping someone's still watching this (old) thread and can shed some light on this question... Is LightWire thread-safe? We're having issues with getBean in ColdSpring not being thread-safe so we're thinking about alternatives.

George.
# Posted By George Bridgeman | 4/22/09 10:43 AM
Hi George,

I know this sounds crazy, but ask on the coldbox list. Luis has added a *lot* of features to the version of lightwire there (it also now supports XML, autowiring, etc) so this is something someone on the coldbox list could probably answer best. FYI, I'll be reviewing their edits and putting them into the main LW project, but it may be a couple of weeks.
# Posted By Peter Bell | 4/22/09 10:49 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.