Class IocUtil
Inheritance
Namespace: Dnn.PersonaBar.Library.Common
Assembly: Dnn.PersonaBar.Library.dll
Syntax
public class IocUtil : object
Methods
| Improve this Doc View SourceGetInstance<TContract>(String)
Declaration
public static TContract GetInstance<TContract>(string name = null)
where TContract : class
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name |
Returns
| Type | Description |
|---|---|
| TContract |
Type Parameters
| Name | Description |
|---|---|
| TContract |
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. |
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 |
|---|---|---|
| System.String | name | Optional name for the contract. Useful when more than once class implements the same contract. |
Returns
| Type | Description |
|---|---|
| System.Boolean | 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.
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 |
|---|---|---|
| System.String | name | Name for the contract. Useful when more than once class implements the same contract. Pass as null when unused. |
| System.Object | instance | Concrete implementation class (must have apublic default constructor). |
Returns
| Type | Description |
|---|---|
| System.Boolean | 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. |