-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Configuring Unity Container
Unity is a very flexible system. It allows customization of all of its aspects. This is some of the things Unity allows to customize:
- Strategies used to build types
- Custom resolvers for specific types (IEnumerable, Array, etc. )
- Default lifetimes for resolved instances
- Different pipelines for type, instance, and factory based resolutions
The list is not exhaustive, there are other things developers could do to adjust behavior of the container.
Configuration through extensions
Although system is highly flexible, adjusting configuration is rather awkward. To change anything, a developer required to create Unity Extension to gain access to internal settings and change defaults.
Configuration the easy way
Unity has built-in extension management mechanism, which among other things has method Configure. By default it allows access to installed extensions and provides a way to configure these as designer intended.
This mechanism could be used to configure Unity as well. There is no reason why it should not be possible to call this method like this:
var internals = container.Configure<IExtensionContext>()and get access to the same information as custom extension.
Implementation
To implement this feature Unity will introduce new interface:
public interface IExtensionContext
{
/// <summary>
/// Pipeline containing processors required to execute registered factories
/// </summary>
IStagedStrategyChain<PipelineProcessor, PipelineStage> FactoryPipeline { get; }
/// <summary>
/// Pipeline containing processors required to manipulate registered instances
/// </summary>
IStagedStrategyChain<PipelineProcessor, PipelineStage> InstancePipeline { get; }
/// <summary>
/// Pipeline containing processors required to create registered types
/// </summary>
IStagedStrategyChain<PipelineProcessor, PipelineStage> TypePipeline { get; }
/// <summary>
/// The policies this container uses.
/// </summary>
/// <remarks>The <see cref="IPolicyList"/> the that container uses to build objects.</remarks>
IPolicyList Policies { get; }
/// <summary>
/// This event is raised when new <see cref="Type"/> is registered.
/// </summary>
event RegistrationEvent TypeRegistered;
/// <summary>
/// This event is raised when new instance is registered.
/// </summary>
event RegistrationEvent InstanceRegistered;
/// <summary>
/// This event is raised when new instance is registered.
/// </summary>
event RegistrationEvent FactoryRegistered;
/// <summary>
/// This event is raised when the <see cref="IUnityContainer.CreateChildContainer"/>
/// method is called and new child container is created. It allow extensions to
/// perform any additional initialization they may require.
/// </summary>
event ChildCreatedEvent ChildContainerCreated;
}