Tuesday, May 02, 2006

Dependency Injection Sounds Dirty!

So there's this fancy-dancy new technology out there called "Spring" and I just had to see what all the hub-bub was about. What is it and what can it do for me? Is it going to cost me an arm and a leg or just a lot of sleepless nights? These were the questions running through my mind as I decided to take a look at what was being heralded as J2EE-lite.

What is it?
Spring is a framework for constructing applications out of related components (java beans). Basically, one defines a domain model to solve a problem, lightens the coupling between domain objects as much as possible (they really do need to know something about each other), and wires the application components together via a configuration (usually an XML file).

Inversion of Control (IoC)
Wiring an application's objects is simply assigning one bean to another (via mutators or constructor arguments). The framework creates the beans defined in the configuration (aka context), initializes them with specified values or other bean references, sets their properties as defined, and provides these objects to your application for use. As the object property's are set by the container and not by the objects themselves, the reponsibility for providing a valid object state falls outside the object itself. This concept is known as Inversion of Control or "Dependency Injection."

Spring is ...
... A very un-intrusive framework for managing your domain objects using IoC. It is an open source tool that is simple to use, provides a plethora of services, and integrates easily with most other java development technologies.

Is it easy to learn? Yes, but like all such containers, there are so many features that it is quite an undertaking to become proficient with it.

Will I be using it? Yes. I am in the process of re-writing a project of mine to use Spring, Hibernate, Ajax and MySQL. I'll keep you up-to-date with the progress as I go along.