Chapter 14. Unity
Menu
- Introducing Unity
- Managing lifetime
- Working with multiple components
- Configuring difficult APIs
In the previous chapter, we looked at Autofac, which is one of the more recent DI CONTAINERS to enter the game. Another contemporary DI CONTAINER is Unity, which we’ll examine in this chapter.
Autofac can be labeled as a second-generation DI CONTAINER because it was conceived and developed directly on .NET 3.5 without any legacy baggage from earlier versions of .NET. Although Unity appeared in roughly the same time frame, it took a more conservative approach. Unity 1.0 was released in May 2008, but targeted .NET 2.0, acknowledging that many development organizations would take their time before upgrading to .NET 3.5.
Unity is an application block from Microsoft’s patterns & practices (p&p) group, but don’t be fooled by the name: an application block is just a reusable library with associated documentation and samples.
Unity and Enterprise Library
Some people tend to mix up Unity and Enterprise Library (another p&p offering), or at least how they relate to each other. Let there be no doubt.
Unity is a stand-alone library. It doesn’t require Enterprise Library.
Enterprise Library, on the other hand, ships with Unity included in the bundle, although even here it simply acts as the default container for Enterprise Library. Other DI CONTAINERS can replace Unity in Enterprise Library if necessary.