Class UnityContainerExtensions
Extension class that adds a set of convenience overloads to the IUnityContainer interface.
Inherited Members
Namespace: Unity
Assembly: Unity.Abstractions.dll
Syntax
public static class UnityContainerExtensions
Methods
| Improve this Doc View SourceBuildUp(IUnityContainer, Type, Object, ResolverOverride[])
Run an existing object through the container and perform injection on it.
Declaration
public static object BuildUp(this IUnityContainer container, Type t, object existing, params ResolverOverride[] resolverOverrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve through. |
Type | t | Type of object to perform injection on. |
Object | existing | Instance to build up. |
ResolverOverride[] | resolverOverrides | Any overrides for the Buildup. |
Returns
Type | Description |
---|---|
Object | The resulting object. By default, this will be |
Remarks
This method is useful when you don't control the construction of an instance (ASP.NET pages or objects created via XAML, for instance) but you still want properties and other injection performed.
This overload uses the default registrations.
BuildUp<T>(IUnityContainer, T, String, ResolverOverride[])
Run an existing object through the container and perform injection on it.
Declaration
public static T BuildUp<T>(this IUnityContainer container, T existing, string name, params ResolverOverride[] resolverOverrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve through. |
T | existing | Instance to build up. |
String | name | name to use when looking up the typemappings and other configurations. |
ResolverOverride[] | resolverOverrides | Any overrides for the Buildup. |
Returns
Type | Description |
---|---|
T | The resulting object. By default, this will be |
Type Parameters
Name | Description |
---|---|
T | Type of object to perform injection on. |
Remarks
This method is useful when you don't control the construction of an instance (ASP.NET pages or objects created via XAML, for instance) but you still want properties and other injection performed.
BuildUp<T>(IUnityContainer, T, ResolverOverride[])
Run an existing object through the container and perform injection on it.
Declaration
public static T BuildUp<T>(this IUnityContainer container, T existing, params ResolverOverride[] resolverOverrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve through. |
T | existing | Instance to build up. |
ResolverOverride[] | resolverOverrides | Any overrides for the buildup. |
Returns
Type | Description |
---|---|
T | The resulting object. By default, this will be |
Type Parameters
Name | Description |
---|---|
T | Type of object to perform injection on. |
Remarks
This method is useful when you don't control the construction of an instance (ASP.NET pages or objects created via XAML, for instance) but you still want properties and other injection performed.
This overload uses the default registrations.
IsRegistered(IUnityContainer, Type)
Check if a particular type has been registered with the container with the default name.
Declaration
public static bool IsRegistered(this IUnityContainer container, Type typeToCheck)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to inspect. |
Type | typeToCheck | Type to check registration for. |
Returns
Type | Description |
---|---|
Boolean | True if this type has been registered, false if not. |
IsRegistered<T>(IUnityContainer)
Check if a particular type has been registered with the container with the default name.
Declaration
public static bool IsRegistered<T>(this IUnityContainer container)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to inspect. |
Returns
Type | Description |
---|---|
Boolean | True if this type has been registered, false if not. |
Type Parameters
Name | Description |
---|---|
T | Type to check registration for. |
IsRegistered<T>(IUnityContainer, String)
Check if a particular type/name pair has been registered with the container.
Declaration
public static bool IsRegistered<T>(this IUnityContainer container, string nameToCheck)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to inspect. |
String | nameToCheck | Name to check registration for. |
Returns
Type | Description |
---|---|
Boolean | True if this type/name pair has been registered, false if not. |
Type Parameters
Name | Description |
---|---|
T | Type to check registration for. |
RegisterFactory(IUnityContainer, Type, Func<IUnityContainer, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | type | Type to register (may be an implemented interface instead of the actual type). |
Func<IUnityContainer, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory(IUnityContainer, Type, Func<IUnityContainer, Type, String, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | type | Type to register (may be an implemented interface instead of the actual type). |
Func<IUnityContainer, Type, String, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on . |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory(IUnityContainer, Type, String, Func<IUnityContainer, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, string name, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | type | Type to register (may be an implemented interface instead of the actual type). |
String | name | Name for registration. |
Func<IUnityContainer, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory(IUnityContainer, Type, String, Func<IUnityContainer, Type, String, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, string name, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | type | Type to register (may be an implemented interface instead of the actual type). |
String | name | Name for registration. |
Func<IUnityContainer, Type, String, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on . |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory<TInterface>(IUnityContainer, Func<IUnityContainer, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Func<IUnityContainer, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory<TInterface>(IUnityContainer, Func<IUnityContainer, Type, String, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Func<IUnityContainer, Type, String, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on . |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory<TInterface>(IUnityContainer, String, Func<IUnityContainer, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, string name, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name for registration. |
Func<IUnityContainer, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterFactory<TInterface>(IUnityContainer, String, Func<IUnityContainer, Type, String, Object>, IFactoryLifetimeManager)
Register a Factory with the container.
Declaration
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, string name, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name for registration. |
Func<IUnityContainer, Type, String, Object> | factory | Predefined to create types
|
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on . |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
This overload does a default registration and has the current container take over the lifetime of the factory.
RegisterInstance(IUnityContainer, Type, Object)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance(this IUnityContainer container, Type t, object instance)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | Type of instance to register (may be an implemented interface instead of the full type). |
Object | instance | Object to returned. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
This overload does a default registration and has the container take over the lifetime of the instance.
RegisterInstance(IUnityContainer, Type, Object, IInstanceLifetimeManager)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance(this IUnityContainer container, Type t, object instance, IInstanceLifetimeManager lifetimeManager)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | Type of instance to register (may be an implemented interface instead of the full type). |
Object | instance | Object to returned. |
IInstanceLifetimeManager | lifetimeManager | LifetimeManager object that controls how this instance will be managed by the container. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
This overload does a default registration (name = null).
RegisterInstance(IUnityContainer, Type, String, Object)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance(this IUnityContainer container, Type t, string name, object instance)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | Type of instance to register (may be an implemented interface instead of the full type). |
String | name | Name for registration. |
Object | instance | Object to returned. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
This overload automatically has the container take ownership of the instance
.
RegisterInstance<TInterface>(IUnityContainer, TInterface)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, TInterface instance)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
TInterface | instance | Object to returned. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
This overload does a default registration and has the container take over the lifetime of the instance.
RegisterInstance<TInterface>(IUnityContainer, TInterface, IInstanceLifetimeManager)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, TInterface instance, IInstanceLifetimeManager lifetimeManager)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
TInterface | instance | Object to returned. |
IInstanceLifetimeManager | lifetimeManager | LifetimeManager object that controls how this instance will be managed by the container. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
This overload does a default registration (name = null).
RegisterInstance<TInterface>(IUnityContainer, String, TInterface)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, string name, TInterface instance)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name for registration. |
TInterface | instance | Object to returned. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
This overload automatically has the container take ownership of the instance
.
RegisterInstance<TInterface>(IUnityContainer, String, TInterface, IInstanceLifetimeManager)
Register an instance with the container.
Declaration
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, string name, TInterface instance, IInstanceLifetimeManager lifetimeManager)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name for registration. |
TInterface | instance | Object to returned. |
IInstanceLifetimeManager | lifetimeManager | LifetimeManager object that controls how this instance will be managed by the container. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TInterface | Type of instance to register (may be an implemented interface instead of the full type). |
Remarks
Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.
RegisterSingleton(IUnityContainer, Type, String, InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type t, string name, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | The Type to configure in the container. |
String | name | Name to use for registration, null if a default registration. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterSingleton(IUnityContainer, Type, Type, String, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type from, Type to, string name, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | from | Type that will be requested. |
Type | to | Type that will actually be returned. |
String | name | Name to use for registration, null if a default registration. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
This method is used to tell the container that when asked for type from
,
actually return an instance of type to
. This is very useful for
getting instances of interfaces.
RegisterSingleton(IUnityContainer, Type, Type, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type from, Type to, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | from | Type that will be requested. |
Type | to | Type that will actually be returned. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
This method is used to tell the container that when asked for type from
,
actually return an instance of type to
. This is very useful for
getting instances of interfaces.
This overload registers a default mapping.
RegisterSingleton(IUnityContainer, Type, InjectionMember[])
Register a type with specific members to be injected.
Declaration
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type t, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | Type this registration is for. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterSingleton<T>(IUnityContainer, String, InjectionMember[])
Register type as a singleton.
Declaration
public static IUnityContainer RegisterSingleton<T>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name that will be used to request the type. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
T | The type to configure injection on. |
RegisterSingleton<T>(IUnityContainer, InjectionMember[])
Register a type with specific members to be injected as singleton.
Declaration
public static IUnityContainer RegisterSingleton<T>(this IUnityContainer container, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
T | Type this registration is for. |
RegisterSingleton<TFrom, TTo>(IUnityContainer, String, InjectionMember[])
Register a type mapping as singleton.
Declaration
public static IUnityContainer RegisterSingleton<TFrom, TTo>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name of this mapping. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TFrom | Type that will be requested. |
TTo | Type that will actually be returned. |
Remarks
This method is used to tell the container that when asked for type TFrom
,
actually return an instance of type TTo
. This is very useful for
getting instances of interfaces.
RegisterSingleton<TFrom, TTo>(IUnityContainer, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterSingleton<TFrom, TTo>(this IUnityContainer container, params InjectionMember[] injectionMembers)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TFrom | Type that will be requested. |
TTo | Type that will actually be returned. |
Remarks
This method is used to tell the container that when asked for type TFrom
,
actually return an instance of type TTo
. This is very useful for
getting instances of interfaces.
This overload registers a default mapping and transient lifetime.
RegisterType(IUnityContainer, Type, String, InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, string name, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | The Type to configure in the container. |
String | name | Name to use for registration, null if a default registration. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterType(IUnityContainer, Type, String, ITypeLifetimeManager, InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | The Type to apply the |
String | name | Name to use for registration, null if a default registration. |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterType(IUnityContainer, Type, Type, String, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, string name, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | from | Type that will be requested. |
Type | to | Type that will actually be returned. |
String | name | Name to use for registration, null if a default registration. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
This method is used to tell the container that when asked for type from
,
actually return an instance of type to
. This is very useful for
getting instances of interfaces.
RegisterType(IUnityContainer, Type, Type, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | from | Type that will be requested. |
Type | to | Type that will actually be returned. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Remarks
This method is used to tell the container that when asked for type from
,
actually return an instance of type to
. This is very useful for
getting instances of interfaces.
This overload registers a default mapping.
RegisterType(IUnityContainer, Type, Type, ITypeLifetimeManager, InjectionMember[])
Register a type mapping with the container, where the created instances will use the given LifetimeManager.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | from | Type that will be requested. |
Type | to | Type that will actually be returned. |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterType(IUnityContainer, Type, InjectionMember[])
Register a type with specific members to be injected.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | Type this registration is for. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterType(IUnityContainer, Type, ITypeLifetimeManager, InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
Type | t | The Type to apply the |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
RegisterType<T>(IUnityContainer, String, InjectionMember[])
Register a LifetimeManager for the given type with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterType<T>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name that will be used to request the type. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
T | The type to configure injection on. |
RegisterType<T>(IUnityContainer, String, ITypeLifetimeManager, InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterType<T>(this IUnityContainer container, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name that will be used to request the type. |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
T | The type to apply the |
RegisterType<T>(IUnityContainer, InjectionMember[])
Register a type with specific members to be injected.
Declaration
public static IUnityContainer RegisterType<T>(this IUnityContainer container, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
T | Type this registration is for. |
RegisterType<T>(IUnityContainer, ITypeLifetimeManager, InjectionMember[])
Register a LifetimeManager for the given type with the container. No type mapping is performed for this type.
Declaration
public static IUnityContainer RegisterType<T>(this IUnityContainer container, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
T | The type to apply the |
RegisterType<TFrom, TTo>(IUnityContainer, String, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name of this mapping. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TFrom | Type that will be requested. |
TTo | Type that will actually be returned. |
Remarks
This method is used to tell the container that when asked for type TFrom
,
actually return an instance of type TTo
. This is very useful for
getting instances of interfaces.
RegisterType<TFrom, TTo>(IUnityContainer, String, ITypeLifetimeManager, InjectionMember[])
Register a type mapping with the container, where the created instances will use the given LifetimeManager.
Declaration
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
String | name | Name to use for registration, null if a default registration. |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TFrom | Type that will be requested. |
TTo | Type that will actually be returned. |
RegisterType<TFrom, TTo>(IUnityContainer, InjectionMember[])
Register a type mapping with the container.
Declaration
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, params InjectionMember[] injectionMembers)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TFrom | Type that will be requested. |
TTo | Type that will actually be returned. |
Remarks
This method is used to tell the container that when asked for type TFrom
,
actually return an instance of type TTo
. This is very useful for
getting instances of interfaces.
This overload registers a default mapping and transient lifetime.
RegisterType<TFrom, TTo>(IUnityContainer, ITypeLifetimeManager, InjectionMember[])
Register a type mapping with the container, where the created instances will use the given LifetimeManager.
Declaration
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
where TTo : TFrom
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to configure. |
ITypeLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
IUnityContainer | The IUnityContainer object that this method was called on. |
Type Parameters
Name | Description |
---|---|
TFrom | Type that will be requested. |
TTo | Type that will actually be returned. |
Resolve(IUnityContainer, Type, ResolverOverride[])
Resolve an instance of the default requested type from the container.
Declaration
public static object Resolve(this IUnityContainer container, Type t, params ResolverOverride[] overrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve from. |
Type | t | Type of object to get from the container. |
ResolverOverride[] | overrides | Any overrides for the resolve call. |
Returns
Type | Description |
---|---|
Object | The retrieved object. |
Resolve<T>(IUnityContainer, String, ResolverOverride[])
Resolve an instance of the requested type with the given name from the container.
Declaration
public static T Resolve<T>(this IUnityContainer container, string name, params ResolverOverride[] overrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve from. |
String | name | Name of the object to retrieve. |
ResolverOverride[] | overrides | Any overrides for the resolve call. |
Returns
Type | Description |
---|---|
T | The retrieved object. |
Type Parameters
Name | Description |
---|---|
T | Type of object to get from the container. |
Resolve<T>(IUnityContainer, ResolverOverride[])
Resolve an instance of the default requested type from the container.
Declaration
public static T Resolve<T>(this IUnityContainer container, params ResolverOverride[] overrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve from. |
ResolverOverride[] | overrides | Any overrides for the resolve call. |
Returns
Type | Description |
---|---|
T | The retrieved object. |
Type Parameters
Name | Description |
---|---|
T | Type of object to get from the container. |
ResolveAll(IUnityContainer, Type, ResolverOverride[])
Return instances of all registered types requested.
Declaration
public static IEnumerable<object> ResolveAll(this IUnityContainer container, Type type, params ResolverOverride[] resolverOverrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve from. |
Type | type | The type requested. |
ResolverOverride[] | resolverOverrides | Any overrides for the resolve calls. |
Returns
Type | Description |
---|---|
IEnumerable<Object> | Set of objects of type |
Remarks
This method is useful if you've registered multiple types with the same Type but different names.
Be aware that this method does NOT return an instance for the default (unnamed) registration.
ResolveAll<T>(IUnityContainer, ResolverOverride[])
Return instances of all registered types requested.
Declaration
public static IEnumerable<T> ResolveAll<T>(this IUnityContainer container, params ResolverOverride[] resolverOverrides)
Parameters
Type | Name | Description |
---|---|---|
IUnityContainer | container | Container to resolve from. |
ResolverOverride[] | resolverOverrides | Any overrides for the resolve calls. |
Returns
Type | Description |
---|---|
IEnumerable<T> | Set of objects of type |
Type Parameters
Name | Description |
---|---|
T | The type requested. |
Remarks
This method is useful if you've registered multiple types with the same Type but different names.
Be aware that this method does NOT return an instance for the default (unnamed) registration.