Unity 2.0 – April 2010
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
|The latest Unity Application Block information can be found at the Unity Application Block site.|
Unity is a lightweight, extensible dependency injection container with support for instance and type interception.
Microsoft Enterprise Library 5.0 Hands-on Labs contain the labs for Unity 2.0, including the interception mechanisms.
On This Page
Feedback and Support
Authors and Contributors
Unity is a lightweight, extensible dependency injection container. It facilitates building loosely coupled applications and provides developers with the following advantages:
- Simplified object creation, especially for hierarchical object structures and dependencies
- Abstraction of requirements; this allows developers to specify dependencies at run time or in configuration and simplify management of crosscutting concerns
- Increased flexibility by deferring component configuration to the container
- Service location capability, which allows clients to store or cache the container
- Instance and type interception
Unity is a general-purpose container for use in any type of Microsoft® .NET Framework-based application. It provides all of the features commonly found in dependency injection mechanisms, including methods to register type mappings and object instances, resolve objects, manage object lifetimes, and inject dependent objects into the parameters of constructors and methods and as the value of properties of objects it resolves.
In addition, Unity is extensible. You can write container extensions that change the behavior of the container, or add new capabilities. For example, the interception feature provided by Unity, which you can use to capture calls to objects and add additional functionality and policies to the target objects, is implemented as a container extension.
The following sections of this guidance describe what Unity can do, when you should choose Unity, and the ways that you can use it in your applications:
- What Does Unity Do? This topic provides a brief overview that will help you to understand what Unity can do, and explains some of the concepts and features it incorporates. It also provides a simple example of the way that you can write code to use Unity.
- When Should I Use Unity? This topic will help you to decide if Unity is suitable for your requirements. It explains the benefits of using Unity, and any alternative techniques you may consider. It also provides details of any limitations of Unity that may affect your decision to use it.
- About This Release of Unity. This topic contains information about the changes in this release, the target audience and system requirements, migration and side-by-side execution, and links to other Microsoft patterns & practices resources.
- Configuring Unity. This topic describes how you can populate a Unity container with the type registrations, mappings, extensions, and other information required by your application.
- Using Unity in Applications. This topic explains how to use Unity in your own applications. It explains how to add Unity to your application, how to resolve objects, and how to take advantage of the many other capabilities of Unity.
- Design of Unity. This topic explains the decisions that went into designing Unity and the rationale behind those decisions.
- Extending and Modifying Unity. This topic explains how to extend Unity and how to modify the source code.
- Deployment and Operations. This topic explains how to deploy and update the Unity assemblies and use the instrumentation exposed by Unity.
A working knowledge of .NET programming is required.
The following are the system requirements for using Unity:
- Operating system: Microsoft Windows® 7 Professional, Enterprise or Ultimate; Windows Server 2003 R2; Windows Server 2008 with Service Pack 2; Windows Server 2008 R2; Windows Vista with Service Pack 2; or Windows XP with Service Pack 3.
- Microsoft .NET Framework 3.5 with Service Pack 1 or Microsoft .NET Framework 4.0.
For a rich development environment, the following are recommended:
- Microsoft Visual Studio® 2008 Development System with Service Pack 1 (any edition) or Microsoft Visual Studio 2010 Development System (any edition).
To run the unit tests, the following are also required:
- Microsoft Visual Studio 2008 Professional, Visual Studio 2008 Team Edition, Visual Studio 2010 Premium, Visual Studio 2010 Professional, or Visual Studio 2010 Ultimate edition.
- Moq v3.1 assemblies.
For the Data Access Application Block, the following is also required:
- A database server running a database that is supported by a .NET Framework 3.5 with Service Pack 1 or .NET Framework 4.0 data provider. This includes SQL Server® 2000 or later, SQL Server 2005 Compact Edition, and Oracle 9i or later. The database server can also run a database that is supported by the .NET Framework 3.5 with Service Pack 1 or the .NET Framework 4.0 data providers for OLE DB or ODBC.
Out of the box, Unity binary assemblies are targeted at .NET Framework 3.5 SP1. Unity solution and project files are provided in Visual Studio 2008 and Visual Studio 2010 formats. For information on building Unity from source and targeting various versions of the .NET framework, see Building Enterprise Library from the Source Code.
Unity was designed to achieve the following goals:
- To promote the principles of modular design through aggressive decoupling of components, business objects, and services
- To raise awareness of the need to maximize testability when designing applications
- To provide a fast and lightweight dependency injection container mechanism for creating new object instances and managing existing object instances
- To expose a compact and intuitive API for developers to use with the container
- To support a wide range of code languages, with method overrides that accept generic parameters where the language supports these
- To implement attribute-driven injection for constructors, property setters, and methods of target objects
- To provide extensibility through custom and third-party container extensions
- To provide the performance required in enterprise-level line-of-business (LOB) applications
The Unity 2.0 release contains the following main changes to the previous release (Unity 1.2 – October 2008):
- Streamlined configuration schema
- A simplified API for static factories and interception
- The capability to add interface implementation through interception
- Additional types of lifetime manager
- Deferred resolution (automatic factories)
- Bug fixes
- A reduction of the number of assemblies
For the full list of changes, please refer to the Release Notes.
For an introduction to dependency injection, see the article Inversion of Control Containers and the Dependency Injection pattern by Martin Fowler.
For information about the key features of Unity, see Unity QuickStarts. This topic demonstrates some of the key features of Unity and is a good starting point for working with Unity.
You can also use the Hands-on Labs to practice Unity capabilities in various contexts. Unity Hands-On Labs are a part of the Microsoft Enterprise Library 5.0 Hands-On Labs set and are available as a separate download.
Unity, like many patterns & practices deliverables, is associated with a community site. On this community site, you can post questions, provide feedback, or connect with other users to share ideas. Community members can also help Microsoft plan and test future releases of Unity, and download additional content such as extensions and training material.
Feedback and Support
Questions? Comments? Suggestions? To provide feedback about Unity, or to get help with any problems, visit the Unity Community site. The message board on the community site is the preferred feedback and support channel because it allows you to share your ideas, questions, and solutions with the entire community. Unity is a guidance offering, designed to be reused, customized, and extended. Code-based guidance is shipped "as is" and without warranties. Customers can obtain support through Microsoft Premier Support Services for a fee, but the code is considered by Microsoft support staff as user-written.
Authors and Contributors
Unity 2.0 was produced by the following individuals:
- Product/Program Management: Grigori Melnik (Microsoft Corporation)
- Architecture/Development: Bob Brumfield and Chris Tavares (Microsoft Corporation), Fernando Simonazzi (Clarius Consulting), Nicolas Botto (Digit Factory) and Olaf Conijn (Olaf Conijn BV)
- Testing: Carlos Farre, Masashi Narumoto and Rohit Sharma (Microsoft Corporation), Nicolas Botto (Digit Factory), Lavanya Selvaraj, Magdelene Sona, Mani Krishnaswami, Meenakshi Krishnamoorthi, Santhosh Panneerselvam, and Ravindra Varman (Infosys Technologies Ltd), Erik Renaud and François Tanguay (nVentive Inc), Rick Carr (DCB Software Testing, Inc)
- Documentation: Alex Homer (Microsoft Corporation) and Dennis DeWitt (Linda Werner ∓ Associates Inc)
- Editing and production: RoAnn Corbisier and Steve Elston (Microsoft Corporation), Nancy Michel (Content Master Ltd.), and Patrick Lanfear and Tom Draper (Twist Creative LLC)
- Release management: Richard Burte (ChannelCatalyst.com, Inc.) and Jennifer Burch (DCB Software Testing, Inc)
- Business administration support: Tracy Emory (Microsoft Corporation)
Many thanks to the following members of the Advisory Board:
- Brian Button (Asynchrony Solutions)
- Kyle Huntley (Avanade)
- David Starr (Elegant Code)
- Wallin Ludwik (Volvo), Bill Wilder (Fidelity)
- Andrej Golcov (Hermes SoftLab)
- John Askew, Nicholas Blumhardt, Martin Bennedik and Serge Baranovsky (Independent)
- Evgeny Sorokin and Ksenia Mukhortova (Intel)
- Scott Nichols (Idaho Central)
- Eng Chong Lim and Isabel Niu (McDonald's Corporation)
- Aaron Hanks, Glenn Block, Hugo Batista, Jason Hogg, Jason Olson, John Czernuszka, Joshy Joseph, Lenny Fenster, Massimo Mascaro, Matthew Podwysocki, Tom Hollander, Piyush Gupta, and Scott Densmore (Microsoft)
- Matthew Buonomano and Nikola Malovic (Monster.com)
- Daniel Piessens and Phill Van Hoven (Red Prairie)
- Walter Wu (Royal Bank of Canada)
Many thanks to the following people who previewed Unity 2.0 and provided valuable feedback and ideas:
- Ade Miller, Blaine Wastell, David Hill, Don Smith, Eugenio Pace, and Mohammad Al-Sabt (Microsoft Corporation)
- Microsoft Unity Container Home Page
- Unity 2.0 for Silverlight
- Microsoft Enterprise Library Home Page
- Microsoft Enterprise Library 5.0