Skip to content

UnityContainerExtension optimization #223

@ENikS

Description

@ENikS

Optimizing UnityContainerExtension

Extensions are implemented as types derived from UnityContainerExtension. Once extension is added to the container it is kept alive until container is disposed.
Some extensions provide custom configuration that could be modified during execution, but for majority of extensions, there is nothing else to do after method Initialize has been called.

The reason these extensions are kept in the container is because type UnityContainerExtension implements interface
IUnityContainerExtensionConfigurator. The container assumes that each installed extension has configuration as well so it keeps it in the list.

Remove IUnityContainerExtensionConfigurator

To separate extensions that provide configuration or should be kept in the container from extensions that could be discarded, class UnityContainerExtension will no longer derive from IUnityContainerExtensionConfigurator. Only extensions that provide custom configuration or require to be kept alive will implement the interface.

Extensions that do not implement it, will be released immediately after method Initialize is called.

Remove method UnityContainerExtension.Remove() as redundant

Starting with v5.x, the container no longer allows removing installed extensions. This method is no longer being used and could be removed from the UnityContainerExtension type.

UnityContainerExtension

The revised UnityContainerExtension type should look as following:

    public abstract class UnityContainerExtension
    {
        public UnityContainer? Container { get; }

        protected ExtensionContext? Context { get; }

        protected abstract void Initialize();
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions