Class IocUtil
Inherited Members
Namespace: Dnn.PersonaBar.Library.Common
Assembly: Dnn.PersonaBar.Library.dll
Syntax
public class IocUtil
Constructors
IocUtil()
Declaration
public IocUtil()
Methods
GetInstanceContracts<TContract>()
Retrieves a concrete implementation of the given interface/contract.
Declaration
public static IEnumerable<TContract> GetInstanceContracts<TContract>() where TContract : class
Returns
| Type | Description |
|---|---|
| IEnumerable<TContract> | A concrete implementation of the given interface (or null if none is registered). |
Type Parameters
| Name | Description |
|---|---|
| TContract | Contract interface for the component to get a concrete implementation of. |
GetInstance<TContract>(string)
Declaration
public static TContract GetInstance<TContract>(string name = null) where TContract : class
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Returns
| Type | Description |
|---|---|
| TContract |
Type Parameters
| Name | Description |
|---|---|
| TContract |
RegisterComponentInstance<TContract>(string, object)
Register a specific instance into the IOC container for later use.
Declaration
public static bool RegisterComponentInstance<TContract>(string name, object instance) where TContract : class
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name for the contract. Useful when more than once class implements the same contract. Pass as null when unused. |
| object | instance | Concrete implementation class (must have apublic default constructor). |
Returns
| Type | Description |
|---|---|
| bool | True if the component was created; false if it was already created in the system. |
Type Parameters
| Name | Description |
|---|---|
| TContract | Contract interface for the component to registr with the IOC container. |
RegisterComponent<TContract, TConcrete>(string)
Register a component into the IOC container for later instantiation.
Declaration
public static bool RegisterComponent<TContract, TConcrete>(string name = null) where TContract : class where TConcrete : class, new()
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Optional name for the contract. Useful when more than once class implements the same contract. |
Returns
| Type | Description |
|---|---|
| bool | True if the component was created; false if it was already created in the system. |
Type Parameters
| Name | Description |
|---|---|
| TContract | Contract interface for the component to registr with the IOC container. |
| TConcrete | Concrete implementation class (must have apublic default constructor). |
Remarks
This helper creates a singleton instance for the contract.