Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity configurability #29

Open
ENikS opened this issue Jun 26, 2020 · 0 comments
Open

Unity configurability #29

ENikS opened this issue Jun 26, 2020 · 0 comments
Assignees

Comments

@ENikS
Copy link
Contributor

ENikS commented Jun 26, 2020

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;
    }
@ENikS ENikS self-assigned this Jun 26, 2020
@ENikS ENikS transferred this issue from unitycontainer/container Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant