Class Container
A dependency injection 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()
Declaration
public void Dispose()
IsRegistered(Type)
Returns true if type is registered in container OR its open generic
definition is registered in container.
Declaration
public bool IsRegistered(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to be ckeck. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsRegistered<T>()
Returns true if T is registered in container OR its open generic
definition is registered in container.
Declaration
public bool IsRegistered<T>()
Returns
| Type | Description |
|---|---|
| bool |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type to be 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 |
| bool | reuse | [Optional] Set to false to create a new instance every time |
Register(Type, Type, Func<object>, bool)
Registers a mapped_type type implemented by imp_type 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 |
| bool | reuse | [Optional] Set to false to create a new instance every time |
RegisterFactoryDelegate<TImplementation>(Func<TImplementation>)
Register 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 into 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)
Register a container interceptor.
Declaration
public void RegisterInterceptor(ContainerInterceptor containerInterceptor)
Parameters
| Type | Name | Description |
|---|---|---|
| ContainerInterceptor | containerInterceptor | The container interceptor. |
RegisterType<TImplementation>(bool)
Registers 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 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 every time Resolve(Type) is called. It overrides |
| bool | reuse | [Optional] Set to false to create a new instance every time |
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 |
| bool | reuse | [Optional] Set to false to create a new instance every time |
Type Parameters
| Name | Description |
|---|---|
| T | The type to be registered. |
| TImplementation | The implementation type to be registered. |
Resolve(Type)
Resolves instance of type from container.
Declaration
public object Resolve(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to be resolved. |
Returns
| Type | Description |
|---|---|
| object | An instance for the specified type OR null if not registered. |
ResolveMany(Type)
Returns an instance for each registered type and subtypes 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 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 container.
Declaration
public T Resolve<T>()
Returns
| Type | Description |
|---|---|
| T | An instance for 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. |