Freigeben über


What Is Unity?

Unity is a lightweight, extensible dependency injection container that supports interception, constructor injection, property injection, and method call injection. You can use Unity in a variety of different ways to help decouple the components of your applications, to maximize coherence in components, and to simplify design, implementation, testing, and administration of these applications.

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 add policies to 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.