Interface IDiContainer
Interface for DI (Dependency Injection) container.
Namespace: Kros.Utils
Assembly: Kros.Utils.dll
Syntax
public interface IDiContainer : IDisposable
Methods
CreateChildContainer()
Create a child container.
Declaration
IDiContainer CreateChildContainer()
Returns
Type | Description |
---|---|
IDiContainer | The new child container. |
Remarks
A child container shares the parent's configuration, but can be configured with different settings or lifetime.
GetInstance(Type)
Resolves the instance of type instanceType
.
Declaration
object GetInstance(Type instanceType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | instanceType | Type to resolve from container. |
Returns
Type | Description |
---|---|
System.Object | Object of type |
GetInstance(Type, String)
Resolves the named instance of type instanceType
.
Declaration
object GetInstance(Type instanceType, string name)
Parameters
Type | Name | Description |
---|---|---|
System.Type | instanceType | Type to resolve from container. |
System.String | name | Name of the desired instance. |
Returns
Type | Description |
---|---|
System.Object | Object of type |
GetInstance<T>()
Resolves the instance of type T
.
Declaration
T GetInstance<T>()
Returns
Type | Description |
---|---|
T | Object of type |
Type Parameters
Name | Description |
---|---|
T | Type to resolve from container. |
GetInstance<T>(String)
Resolves the named instance of type T
.
Declaration
T GetInstance<T>(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the desired instance. |
Returns
Type | Description |
---|---|
T | Object of type |
Type Parameters
Name | Description |
---|---|
T | Type to resolve from container. |
Register<T>()
Registers a class type.
Declaration
IDiContainer Register<T>()
Returns
Type | Description |
---|---|
IDiContainer | Container instance for fluent registration. |
Type Parameters
Name | Description |
---|---|
T | Class type. |
Register<T>(Func<IDiContainer, T>)
Register interface or class type using lambda function.
Declaration
IDiContainer Register<T>(Func<IDiContainer, T> lambda)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IDiContainer, T> | lambda | Function which takes current DI container as parameter and creates a new instance of |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Interface or class type. |
Register<T>(String)
Registers a class type with name name
.
Declaration
IDiContainer Register<T>(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the registered class type. |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Class type. |
Register<T>(String, Func<IDiContainer, T>)
Register named interface or class type using lambda function.
Declaration
IDiContainer Register<T>(string name, Func<IDiContainer, T> lambda)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the registered interface or class type. |
System.Func<IDiContainer, T> | lambda |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Interface or class type. |
Register<TFrom, TTo>()
Registers a interface-class pair.
Declaration
IDiContainer Register<TFrom, TTo>()
where TTo : TFrom
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
TFrom | Registered interface. |
TTo | Registered class type that implements |
Register<TFrom, TTo>(String)
Registers a named interface-class pair.
Declaration
IDiContainer Register<TFrom, TTo>(string name)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the registered interface. |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
TFrom | |
TTo |
RegisterInstance<T>()
Registers class type as singleton.
Declaration
IDiContainer RegisterInstance<T>()
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Registered class type. |
RegisterInstance<T>(T)
Registers class instance.
Declaration
IDiContainer RegisterInstance<T>(T instance)
Parameters
Type | Name | Description |
---|---|---|
T | instance | Registered instance. |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Registered class type. |
RegisterInstance<T>(Func<IDiContainer, T>)
Registers class instance as sigleton using function.
Declaration
IDiContainer RegisterInstance<T>(Func<IDiContainer, T> lambda)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IDiContainer, T> | lambda |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Registered class type. |
RegisterInstance<T>(String)
Registers class type with name name
as singleton.
Declaration
IDiContainer RegisterInstance<T>(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the registered class type. |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Registered class type. |
RegisterInstance<T>(String, T)
Registers class instance.
Declaration
IDiContainer RegisterInstance<T>(string name, T instance)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the registered class type. |
T | instance | Registered instance. |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Registered class type. |
RegisterInstance<T>(String, Func<IDiContainer, T>)
Registers named class instance as sigleton using function.
Declaration
IDiContainer RegisterInstance<T>(string name, Func<IDiContainer, T> lambda)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name, under which is type registered. |
System.Func<IDiContainer, T> | lambda |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
T | Registered class type. |
RegisterInstance<TFrom, TTo>()
Registers a interface-class pair as singleton.
Declaration
IDiContainer RegisterInstance<TFrom, TTo>()
where TTo : TFrom
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
TFrom | |
TTo |
RegisterInstance<TFrom, TTo>(String)
Registers a named interface to class type pair. class type TTo
as a singleton.
Declaration
IDiContainer RegisterInstance<TFrom, TTo>(string name)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the registered class type. |
Returns
Type | Description |
---|---|
IDiContainer |
Type Parameters
Name | Description |
---|---|
TFrom | |
TTo |