DIAB is now Unity

First of all, we finally came up with a name for the DI container we are building. A drum roll, please… We’ve decided to call it “Unity” as a container that epitomizes a quality of one (system) being, comprising, or consisting of a number (of parts/components). It may not be as descriptive as other blocks but it fits with our vision. We also wanted to distinguish it from other application blocks.

A short description of Unity is a lightweight, extensible dependency injection container.

Unity will provide mechanisms for building instances of objects, which may contain other dependent object instances.

Unity will expose Register methods that support configuring the container with mappings and objects (including singleton instances), and Get methods to return instances of built objects that contain any dependent objects. Note we have purposefully designed the API to support the “fluent interface” pattern. Here’s a preview of the fundamental features of the Unity API, these are very tentative as we are still working on the semantics:

public class UnityContainer : IDisposable {

// getting objects

public T Get<T>(string key){}

public IEnumerable<T> GetAll<T>(){}

// type mapping

public UnityContainer Register<TFrom, TTo>(string key) where TTo : TFrom {}

// singleton support

public UnityContainer SetSingleton<T>(string key) {}

// support for registering existing objects

public UnityContainer RegisterInstance<T>(T existing, string key, bool overload) {}

// running existing objects through the container

public T BuildUp<T>(T existing, string key){}

}

There are also overloads for non-generics.

So, a typical usage scenario will be:

UnityContainer container = new UnityContainer()

                  .Register<ILogger, TraceLogger>()

                  .Register<ISomething, Something>()
.Register<ISomethingElse, SomethingElse>();

container.Get<ISomething>();

As mentioned in our previous postings, Unity will be released in two forms - standalone container and as a part of Enterprise Library 4, with the existing blocks refactored to take advantage of Unity.

Unity will support extensibility via the ContainerExtension mechanism to allow third parties to add support for other on-demand features at runtime, such as event broker.