Class UnityContainerExtensions
- Namespace
- Unity
- Assembly
- Unity.Abstractions.dll
Extension class that adds a set of convenience overloads to the IUnityContainer interface.
public static class UnityContainerExtensions
- Inheritance
-
UnityContainerExtensions
- Inherited Members
Methods
BuildUp(IUnityContainer, Type, object, params ResolverOverride[])
Run an existing object through the container and perform injection on it.
public static object BuildUp(this IUnityContainer container, Type t, object existing, params ResolverOverride[] resolverOverrides)
Parameters
container
IUnityContainerContainer to resolve through.
t
TypeType of object to perform injection on.
existing
objectInstance to build up.
resolverOverrides
ResolverOverride[]Any overrides for the Buildup.
Returns
- object
The resulting object. By default, this will be
existing
, but container extensions may add things like automatic proxy creation which would cause this to return a different object (but still type compatible witht
).
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, params ResolverOverride[])
Run an existing object through the container and perform injection on it.
public static T BuildUp<T>(this IUnityContainer container, T existing, string name, params ResolverOverride[] resolverOverrides)
Parameters
container
IUnityContainerContainer to resolve through.
existing
TInstance to build up.
name
stringname to use when looking up the typemappings and other configurations.
resolverOverrides
ResolverOverride[]Any overrides for the Buildup.
Returns
- T
The resulting object. By default, this will be
existing
, but container extensions may add things like automatic proxy creation which would cause this to return a different object (but still type compatible withT
).
Type Parameters
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, params ResolverOverride[])
Run an existing object through the container and perform injection on it.
public static T BuildUp<T>(this IUnityContainer container, T existing, params ResolverOverride[] resolverOverrides)
Parameters
container
IUnityContainerContainer to resolve through.
existing
TInstance to build up.
resolverOverrides
ResolverOverride[]Any overrides for the buildup.
Returns
- T
The resulting object. By default, this will be
existing
, but container extensions may add things like automatic proxy creation which would cause this to return a different object (but still type compatible withT
).
Type Parameters
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.
public static bool IsRegistered(this IUnityContainer container, Type typeToCheck)
Parameters
container
IUnityContainerContainer to inspect.
typeToCheck
TypeType to check registration for.
Returns
- bool
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.
public static bool IsRegistered<T>(this IUnityContainer container)
Parameters
container
IUnityContainerContainer to inspect.
Returns
- bool
True if this type has been registered, false if not.
Type Parameters
T
Type to check registration for.
IsRegistered<T>(IUnityContainer, string)
Check if a particular type/name pair has been registered with the container.
public static bool IsRegistered<T>(this IUnityContainer container, string nameToCheck)
Parameters
container
IUnityContainerContainer to inspect.
nameToCheck
stringName to check registration for.
Returns
- bool
True if this type/name pair has been registered, false if not.
Type Parameters
T
Type to check registration for.
RegisterFactory(IUnityContainer, Type, Func<IUnityContainer, object>, IFactoryLifetimeManager)
Register a Factory with the container.
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
type
TypeType to register (may be an implemented interface instead of the actual type).
factory
Func<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager
Returns
- 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.
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
type
TypeType to register (may be an implemented interface instead of the actual type).
factory
Func<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager
Returns
- 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.
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, string name, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
type
TypeType to register (may be an implemented interface instead of the actual type).
name
stringName for registration.
factory
Func<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager
Returns
- 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.
public static IUnityContainer RegisterFactory(this IUnityContainer container, Type type, string name, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
type
TypeType to register (may be an implemented interface instead of the actual type).
name
stringName for registration.
factory
Func<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. This manager has to derive from IFactoryLifetimeManager
Returns
- 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.
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
factory
Func<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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.
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
factory
Func<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on .
Type Parameters
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.
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, string name, Func<IUnityContainer, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
name
stringName for registration.
factory
Func<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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.
public static IUnityContainer RegisterFactory<TInterface>(this IUnityContainer container, string name, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager = null)
Parameters
container
IUnityContainerContainer to configure.
name
stringName for registration.
factory
Func<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>
lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance. If no manager is provided, container uses Transient manager.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on .
Type Parameters
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.
public static IUnityContainer RegisterInstance(this IUnityContainer container, Type t, object instance)
Parameters
container
IUnityContainerContainer to configure.
t
TypeType of instance to register (may be an implemented interface instead of the full type).
instance
objectObject to returned.
Returns
- 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.
public static IUnityContainer RegisterInstance(this IUnityContainer container, Type t, object instance, IInstanceLifetimeManager lifetimeManager)
Parameters
container
IUnityContainerContainer to configure.
t
TypeType of instance to register (may be an implemented interface instead of the full type).
instance
objectObject to returned.
lifetimeManager
IInstanceLifetimeManagerLifetimeManager object that controls how this instance will be managed by the container.
Returns
- 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.
public static IUnityContainer RegisterInstance(this IUnityContainer container, Type t, string name, object instance)
Parameters
container
IUnityContainerContainer to configure.
t
TypeType of instance to register (may be an implemented interface instead of the full type).
name
stringName for registration.
instance
objectObject to returned.
Returns
- 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, string, TInterface)
Register an instance with the container.
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, string name, TInterface instance)
Parameters
container
IUnityContainerContainer to configure.
name
stringName for registration.
instance
TInterfaceObject to returned.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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.
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, string name, TInterface instance, IInstanceLifetimeManager lifetimeManager)
Parameters
container
IUnityContainerContainer to configure.
name
stringName for registration.
instance
TInterfaceObject to returned.
lifetimeManager
IInstanceLifetimeManagerLifetimeManager object that controls how this instance will be managed by the container.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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.
RegisterInstance<TInterface>(IUnityContainer, TInterface)
Register an instance with the container.
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, TInterface instance)
Parameters
container
IUnityContainerContainer to configure.
instance
TInterfaceObject to returned.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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.
public static IUnityContainer RegisterInstance<TInterface>(this IUnityContainer container, TInterface instance, IInstanceLifetimeManager lifetimeManager)
Parameters
container
IUnityContainerContainer to configure.
instance
TInterfaceObject to returned.
lifetimeManager
IInstanceLifetimeManagerLifetimeManager object that controls how this instance will be managed by the container.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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).
RegisterSingleton(IUnityContainer, Type, string, params InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type t, string name, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
t
TypeThe Type to configure in the container.
name
stringName to use for registration, null if a default registration.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterSingleton(IUnityContainer, Type, Type, string, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type from, Type to, string name, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
from
TypeType that will be requested.
to
TypeType that will actually be returned.
name
stringName to use for registration, null if a default registration.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- 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, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type from, Type to, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
from
TypeType that will be requested.
to
TypeType that will actually be returned.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- 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, params InjectionMember[])
Register a type with specific members to be injected.
public static IUnityContainer RegisterSingleton(this IUnityContainer container, Type t, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
t
TypeType this registration is for.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterSingleton<T>(IUnityContainer, string, params InjectionMember[])
Register type as a singleton.
public static IUnityContainer RegisterSingleton<T>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
name
stringName that will be used to request the type.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
T
The type to configure injection on.
RegisterSingleton<T>(IUnityContainer, params InjectionMember[])
Register a type with specific members to be injected as singleton.
public static IUnityContainer RegisterSingleton<T>(this IUnityContainer container, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
T
Type this registration is for.
RegisterSingleton<TFrom, TTo>(IUnityContainer, string, params InjectionMember[])
Register a type mapping as singleton.
public static IUnityContainer RegisterSingleton<TFrom, TTo>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers) where TTo : TFrom
Parameters
container
IUnityContainerContainer to configure.
name
stringName of this mapping.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterSingleton<TFrom, TTo>(this IUnityContainer container, params InjectionMember[] injectionMembers) where TTo : TFrom
Parameters
container
IUnityContainerContainer to configure.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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, params InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, string name, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
t
TypeThe Type to configure in the container.
name
stringName to use for registration, null if a default registration.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterType(IUnityContainer, Type, string, ITypeLifetimeManager, params InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
t
TypeThe Type to apply the
lifetimeManager
to.name
stringName to use for registration, null if a default registration.
lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterType(IUnityContainer, Type, Type, string, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, string name, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
from
TypeType that will be requested.
to
TypeType that will actually be returned.
name
stringName to use for registration, null if a default registration.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- 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, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
from
TypeType that will be requested.
to
TypeType that will actually be returned.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- 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, params InjectionMember[])
Register a type mapping with the container, where the created instances will use the given LifetimeManager.
public static IUnityContainer RegisterType(this IUnityContainer container, Type from, Type to, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
from
TypeType that will be requested.
to
TypeType that will actually be returned.
lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterType(IUnityContainer, Type, params InjectionMember[])
Register a type with specific members to be injected.
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
t
TypeType this registration is for.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterType(IUnityContainer, Type, ITypeLifetimeManager, params InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterType(this IUnityContainer container, Type t, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
t
TypeThe Type to apply the
lifetimeManager
to.lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
RegisterType<T>(IUnityContainer, string, params InjectionMember[])
Register a LifetimeManager for the given type with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterType<T>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
name
stringName that will be used to request the type.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
T
The type to configure injection on.
RegisterType<T>(IUnityContainer, string, ITypeLifetimeManager, params InjectionMember[])
Register a LifetimeManager for the given type and name with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterType<T>(this IUnityContainer container, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
name
stringName that will be used to request the type.
lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
T
The type to apply the
lifetimeManager
to.
RegisterType<T>(IUnityContainer, params InjectionMember[])
Register a type with specific members to be injected.
public static IUnityContainer RegisterType<T>(this IUnityContainer container, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
T
Type this registration is for.
RegisterType<T>(IUnityContainer, ITypeLifetimeManager, params InjectionMember[])
Register a LifetimeManager for the given type with the container. No type mapping is performed for this type.
public static IUnityContainer RegisterType<T>(this IUnityContainer container, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
container
IUnityContainerContainer to configure.
lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
T
The type to apply the
lifetimeManager
to.
RegisterType<TFrom, TTo>(IUnityContainer, string, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, string name, params InjectionMember[] injectionMembers) where TTo : TFrom
Parameters
container
IUnityContainerContainer to configure.
name
stringName of this mapping.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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, params InjectionMember[])
Register a type mapping with the container, where the created instances will use the given LifetimeManager.
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers) where TTo : TFrom
Parameters
container
IUnityContainerContainer to configure.
name
stringName to use for registration, null if a default registration.
lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
RegisterType<TFrom, TTo>(IUnityContainer, params InjectionMember[])
Register a type mapping with the container.
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, params InjectionMember[] injectionMembers) where TTo : TFrom
Parameters
container
IUnityContainerContainer to configure.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
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, params InjectionMember[])
Register a type mapping with the container, where the created instances will use the given LifetimeManager.
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers) where TTo : TFrom
Parameters
container
IUnityContainerContainer to configure.
lifetimeManager
ITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
Resolve(IUnityContainer, Type, params ResolverOverride[])
Resolve an instance of the default requested type from the container.
public static object Resolve(this IUnityContainer container, Type t, params ResolverOverride[] overrides)
Parameters
container
IUnityContainerContainer to resolve from.
t
TypeType of object to get from the container.
overrides
ResolverOverride[]Any overrides for the resolve call.
Returns
- object
The retrieved object.
ResolveAll(IUnityContainer, Type, params ResolverOverride[])
Return instances of all registered types requested.
public static IEnumerable<object> ResolveAll(this IUnityContainer container, Type type, params ResolverOverride[] resolverOverrides)
Parameters
container
IUnityContainerContainer to resolve from.
type
TypeThe type requested.
resolverOverrides
ResolverOverride[]Any overrides for the resolve calls.
Returns
- IEnumerable<object>
Set of objects of type
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, params ResolverOverride[])
Return instances of all registered types requested.
public static IEnumerable<T> ResolveAll<T>(this IUnityContainer container, params ResolverOverride[] resolverOverrides)
Parameters
container
IUnityContainerContainer to resolve from.
resolverOverrides
ResolverOverride[]Any overrides for the resolve calls.
Returns
- IEnumerable<T>
Set of objects of type
T
.
Type Parameters
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.
Resolve<T>(IUnityContainer, string, params ResolverOverride[])
Resolve an instance of the requested type with the given name from the container.
public static T Resolve<T>(this IUnityContainer container, string name, params ResolverOverride[] overrides)
Parameters
container
IUnityContainerContainer to resolve from.
name
stringName of the object to retrieve.
overrides
ResolverOverride[]Any overrides for the resolve call.
Returns
- T
The retrieved object.
Type Parameters
T
Type of object to get from the container.
Resolve<T>(IUnityContainer, params ResolverOverride[])
Resolve an instance of the default requested type from the container.
public static T Resolve<T>(this IUnityContainer container, params ResolverOverride[] overrides)
Parameters
container
IUnityContainerContainer to resolve from.
overrides
ResolverOverride[]Any overrides for the resolve call.
Returns
- T
The retrieved object.
Type Parameters
T
Type of object to get from the container.