Using Container Extensions

Retired Content

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.

You can create your own custom container extensions, or use container extensions created by third parties, with the Unity Application Block. The application block includes a demonstration of a container extension that implements the Publish/Subscribe design pattern for events (for more information, see Walkthrough: The Unity Event Broker Extension QuickStart). Unity also uses default container extensions to implement its own functionality.


Ff648572.note(en-us,PandP.10).gifNote:
For details of how to create a container extension, see Creating Container Extensions. For information about third-party container extensions, see the Unity Community Site on CodePlex.


You can add a custom extension to the Unity container in one of two ways:

You can also access configuration information for an extension that exposes such information. For details, see Accessing Configuration Information for Extensions.

Container extensions will usually add strategies and policies to the container, as described in the topic Creating Container Extensions. However, extensions can expose configuration interfaces that allow them to read and expose configuration information. The extension must provide its own features to read and manage configuration information.

To access the configuration information for an extension, use the Configure method. This method of the UnityContainer class walks the list of extensions added to the container and returns the first one that implements the type you specify in the parameter of the Configure method. The method returns the required configuration interface, or it returns null (Nothing in Visual Basic) if the configuration type is not found.

There are two overrides of the Configure method. You can specify the extension type in the generic overload as a "configurator" (a class that implements the IUnityContainerExtensionConfigurator interface), or you can use the non-generic overload that accepts and returns an Object type. The following code shows both overrides of the Configure method used to retrieve the configuration as a type named MyConfigInterface.

// using a "configurator" where MyConfigInterface implements 
// the IUnityContainerExtensionConfigurator interface
MyConfigInterface configurator = container.Configure<MyConfigInterface>();

// using an Object type
Object config = container.Configure(typeof(MyConfigInterface));

For more information about configuration for container extensions, see Creating Container Extensions.


Show: