This project is read-only.

Microsoft Unity Application Block (Unity) 2.0 Beta2 - March 2010 Change Log

Unity 2.0 is a new release of the Microsoft patterns & practices Unity dependency injection and interception system.

Breaking Changes to Unity (Desktop Only)

  • Unity 2.0 uses a new streamlined configuration schema for Configuring Unity. Partial backward compatibility is provided for previous configuration schemas. The new schema breaks previous container extension configurations using <extensionConfig>.
  • Unity 2.0 configuration API change:
The previous API used to load container configuration has been deprecated. Previous versions used the following approach:
IUnityContainer myContainer = new UnityContainer();
UnityConfigurationSection section 
    = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

In Unity 2.0, you have the two choices. You can use ConfigurationManager and Configure to load a given container from a specific named configuration section as shown in the following example.
IUnityContainer myContainer = new UnityContainer();
UnityConfigurationSection section
    = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.ConfigureContainer(myContainer, "containerName");

You can also use LoadConfiguration to load a given named container from the default configuration section as shown in the following example.
IUnityContainer myContainer = new UnityContainer();

Note: There are several overloads of the new LoadConfiguration extension method. See Using Design Time Configuration for more information in the included CHM file.

Changes in Unity (Desktop only)

The following changes are implemented in this release (Desktop only):
  • The ObjectBuilder generic dependency injection mechanism, which was previously distributed as a separate assembly, is now integrated with Unity. You no longer need to reference the ObjectBuilder assembly in your projects.
  • The StaticFactory.StaticFactoryExtension to Unity, which allows you to specify a factory function that the container will use to create an object, was shipped as a separate project in Unity 1.2. In this release, it is contained within the main Unity assembly but is deprecated. Use the new InjectionFactory class.
  • Unity provides a new interception process and provides interceptors that enable you to intercept calls to objects and attach behaviors to the intercepted methods. A Behaviors pipeline is used instead of the previous call handlers pipeline. Interception is supported with or without a dependency injection container. See Interception With Unity.

Changes in Unity (Desktop and Silverlight editions)

  • New InjectionFactory class has been added. It enables you specify a factory method that the container will use to create the object. It is an easier way to accomplish the same task as the old StaticFactory.StaticFactoryExtension.
  • A HierarchicalLifetimeManager is provided to register an object in the parent container such that each child container resolves its own instance of the object instead of sharing one with the parent. See Understanding Lifetime Managers in the included CHM file.
  • Dependencies can be made optional by using the <optional> element in configuration files, the [OptionalDependency] attribute in your code or the OptionalParameter API. See Annotating Objects for Property Setter Injection in the included CHM file.
  • Unity now provides the ability to specify parameter values for constructors, or specific values for properties, at Resolve time. These values override what the container would have otherwise supplied. ParameterOverride, PropertyOveride and DependencyOverride, are ResolverOverride implementations that provide support for overriding the registration information for resolving instances of types. See Resolving Objects By Using Overrides topic in the included CHM file.
  • A PerResolveLifetimeManager registers an object such that the behavior is like a TransientLifetimeManager, but also provides a signal to the default build plan, marking the type so that instances are reused across the build up object graph. See Understanding Lifetime Managers in the included CHM file.
  • Registrations property and IsRegistered method added. These let you query the container and retrieve information about what is currently registered, see Retrieving Container Information topic.
  • Specifying a resolved array without providing any members will result in an empty (zero length) array.
    • In a configuration file, the <array /> element with no child elements will generate a zero-length array for both generic and non-generic types. If you want to resolve all configured types to populate the array (effectively invoking the ResolveAll behavior), you must use a <dependency /> element instead.
    • When performing run time configuration, the GenericArrayParameter and GenericResolvedArrayParameter classes will generate a zero length array if you do not specify the members for the array. Instead, use the GenericParameter class and specify the array type followed by the appropriate brackets to indicate an array type in the language you are using. For example, GenericParameter("T[]") in C# or GenericParameter("T()") in Visual Basic.

Last edited Mar 16, 2010 at 2:55 AM by gmelnik, version 4