Search Results for

    Show / Hide Table of Contents

    Class Container

    A dependency injection container.

    Inheritance
    object
    Container
    Namespace: Evergine.Framework
    Assembly: Evergine.Framework.dll
    Syntax
    public class Container

    Constructors

    Container()

    Initializes a new instance of the Container class.

    Declaration
    public Container()

    Methods

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

    Declaration
    public void Dispose()

    IsRegistered(Type)

    Returns true if type is registered in the container or its open generic definition is registered in the container.

    Declaration
    public bool IsRegistered(Type type)
    Parameters
    Type Name Description
    Type type

    The type to be checked.

    Returns
    Type Description
    bool

    true if type is registered in the container or its open generic definition is registered in the container; otherwise, false.

    IsRegistered<T>()

    Returns true if T is registered in the container OR its open generic definition is registered in the container.

    Declaration
    public bool IsRegistered<T>()
    Returns
    Type Description
    bool

    true if T is registered in the container OR its open generic definition is registered in the container; otherwise, false.

    Type Parameters
    Name Description
    T

    The type to check.

    Register(Type, Func<object>, bool)

    Registers the type type for all implemented internal interfaces and base classes.

    Declaration
    public void Register(Type type, Func<object> factoryDelegate = null, bool reuse = true)
    Parameters
    Type Name Description
    Type type

    The type to be registered.

    Func<object> factoryDelegate

    [Optional] Custom method to be used every time Resolve(Type) is called. It overrides reuse.

    bool reuse

    [Optional] Set to false to create a new instance every time type is resolved. Ignored if factoryDelegate is set.

    Register(Type, Type, Func<object>, bool)

    Registers a mapped_type implemented by imp_type.

    Declaration
    public void Register(Type mapped_type, Type imp_type, Func<object> factoryDelegate = null, bool reuse = true)
    Parameters
    Type Name Description
    Type mapped_type

    The type to be registered.

    Type imp_type

    The implementation type to be registered.

    Func<object> factoryDelegate

    [Optional] Custom method to be used every time Resolve(Type) is called. It overrides reuse.

    bool reuse

    [Optional] Set to false to create a new instance every time mapped_type is resolved. Ignored if factoryDelegate is set.

    RegisterFactoryDelegate<TImplementation>(Func<TImplementation>)

    Registers a delegate to create instances.

    Declaration
    [Obsolete("Use Register<TImplementation>(Func<object> factoryDelegate) method instead")]
    public void RegisterFactoryDelegate<TImplementation>(Func<TImplementation> factoryMethod)
    Parameters
    Type Name Description
    Func<TImplementation> factoryMethod

    The factory method.

    Type Parameters
    Name Description
    TImplementation

    The object type.

    RegisterInstance<TImplementation>(TImplementation)

    Stores the externally-created instance in the singleton.

    Declaration
    public void RegisterInstance<TImplementation>(TImplementation instance)
    Parameters
    Type Name Description
    TImplementation instance

    The externally-created instance.

    Type Parameters
    Name Description
    TImplementation

    The implementation type to be registered.

    RegisterInterceptor(ContainerInterceptor)

    Registers a container interceptor.

    Declaration
    public void RegisterInterceptor(ContainerInterceptor containerInterceptor)
    Parameters
    Type Name Description
    ContainerInterceptor containerInterceptor

    The container interceptor.

    RegisterType<TImplementation>(bool)

    Registers the implementation type TImplementation for all implemented internal interfaces and base classes.

    Declaration
    [Obsolete("Use Register<TImplementation>() method instead")]
    public void RegisterType<TImplementation>(bool singleton = true) where TImplementation : new()
    Parameters
    Type Name Description
    bool singleton

    Set to false to create a new instance every time the type is resolved. Defaults to true.

    Type Parameters
    Name Description
    TImplementation

    The implementation type to be registered.

    Register<TImplementation>(Func<TImplementation>, bool)

    Registers the implementation type TImplementation for all implemented internal interfaces and base classes.

    Declaration
    public void Register<TImplementation>(Func<TImplementation> factoryDelegate = null, bool reuse = true)
    Parameters
    Type Name Description
    Func<TImplementation> factoryDelegate

    [Optional] Custom method to be used each time Resolve(Type) is called. It overrides reuse.

    bool reuse

    [Optional] Set to false to create a new instance each time TImplementation is resolved. Ignored if factoryDelegate is set.

    Type Parameters
    Name Description
    TImplementation

    The implementation type to be registered.

    Register<T, TImplementation>(Func<TImplementation>, bool)

    Registers a T type implemented by TImplementation type.

    Declaration
    public void Register<T, TImplementation>(Func<TImplementation> factoryDelegate = null, bool reuse = true)
    Parameters
    Type Name Description
    Func<TImplementation> factoryDelegate

    [Optional] Custom method to be used every time Resolve(Type) is called. It overrides reuse.

    bool reuse

    [Optional] Set to false to create a new instance every time TImplementation is resolved. Ignored if factoryDelegate is set.

    Type Parameters
    Name Description
    T

    The type to be registered.

    TImplementation

    The implementation type to be registered.

    Resolve(Type)

    Resolves an instance of the specified type from the container.

    Declaration
    public object Resolve(Type type)
    Parameters
    Type Name Description
    Type type

    The type to be resolved.

    Returns
    Type Description
    object

    An instance of the specified type, or null if not registered.

    ResolveMany(Type)

    Returns an instance for each registered type and subtype of .

    Declaration
    public IEnumerable<object> ResolveMany(Type type)
    Parameters
    Type Name Description
    Type type

    The type to be resolved.

    Returns
    Type Description
    IEnumerable<object>

    An enumerable collection containing all registered instances.

    ResolveMany<T>()

    Returns all registered instances of type T from the container.

    Declaration
    public IEnumerable<T> ResolveMany<T>()
    Returns
    Type Description
    IEnumerable<T>

    An enumerable collection containing all registered instances.

    Type Parameters
    Name Description
    T

    The type to be resolved.

    Resolve<T>()

    Resolves instance of type T from the container.

    Declaration
    public T Resolve<T>()
    Returns
    Type Description
    T

    An instance of the specified type or null if not registered.

    Type Parameters
    Name Description
    T

    The type to be resolved.

    Unregister(Type)

    Removes specified registration from container.

    Declaration
    public void Unregister(Type type)
    Parameters
    Type Name Description
    Type type

    The type to be unregistered.

    Unregister<T>()

    Removes specified registration from container.

    Declaration
    public void Unregister<T>()
    Type Parameters
    Name Description
    T

    The type to be unregistered.

    Unregister<T>(T)

    Removes specified registration from container.

    Declaration
    public void Unregister<T>(T instance)
    Parameters
    Type Name Description
    T instance

    The intance to be unregistered.

    Type Parameters
    Name Description
    T

    The type to be unregistered.

    Extension Methods

    ReflectionHelper.GetMemberAssembly(object)
    ReflectionHelper.GetTypeName(object)
    In this article
    Back to top
    Generated by DocFX