I'm not dissing MS Unity, Microsoft's new IoC Container - I'm really going to give it a chance. Rather, I'm talking about the reaction to it on the Yahoo! [altdotnet] group.
I have just spent most of the morning following a thread on the [altdotnet] mailing list titled "Unity" Ioc from Microsoft has been released in CTP... And it has. But in retrospect, based on the thread, "Unity" was a very ironic name choice for the tool. This is a very long thread that is involving dozens of folks. It started off by comparing the functionality in Unity to functionality in other IoC containers, mostly Castle Windsor & StructureMap. The Spring.NET crowd has been strangely silent.
Later in the thread, however, the "altdotnet"ness of the list has begun to show its colors. Passions have arisen and tempered. Staunch defenders of each "side" (and there are more than two sides to this polygon) have held their ground while alternately being gracious one minute and on-the-attack the next. It's the ultimate Reality TV... except that it's not TV, of course.
I've wasted too much time trying to follow this thread and I declare that I am DONE with it. Not that the task wasn't worth it. I've learned a lot about IoC that I hadn't know before. I'm familiar with Windsor, and I've downloaded Unity and played around with it as well. The really great gem that I have just discovered is StructureMap. I just love the "fluent interface" it has - much like is available in Rhino.Mocks. Fun, geeky stuff.
I thought it would be a useful exercise to compare "Hello, World!" scenarios between the big-four (and, yes, I'm including Unity as part of that):
| Function | Castle Windsor | StructureMap | Unity | Spring.NET |
| Putting an interface and concrete type into the IoC container | WindsorContainer. AddComponent() | StructureMapConfiguration. BuildInstancesOf(). TheDefaultIsConcreteType() | UnityContainer. Register() | N/A - Spring doesn't support XMLless config (that I could find). Those Java guys just have a love affair with XML, I guess |
| Getting a concrete type for a given interface | Resolve() | ObjectFactory. GetInstance() | UnityContainer. Get() |
| Default items are | Singleton | separate instance | separate instances |
The fluent-interface of StructureMap is so nice. Yes, it's longer to type, but hey, that's what IntelliSense is fore, and that will make it easier for new developers to discover.
Incidentally, Unity looks an awful lot like Windsor in its syntax, and it was mentioned in the aforementioned thread that the PM on the Unity project is a big Windsor fan.
Apology: I just couldn't resist the lolcats thing, it was just too apropos. This is my one (1), lifetime, self-imposed limit.