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
containerIUnityContainerContainer to resolve through.
tTypeType of object to perform injection on.
existingobjectInstance to build up.
resolverOverridesResolverOverride[]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
containerIUnityContainerContainer to resolve through.
existingTInstance to build up.
namestringname to use when looking up the typemappings and other configurations.
resolverOverridesResolverOverride[]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
TType 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
containerIUnityContainerContainer to resolve through.
existingTInstance to build up.
resolverOverridesResolverOverride[]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
TType 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
containerIUnityContainerContainer to inspect.
typeToCheckTypeType 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
containerIUnityContainerContainer to inspect.
Returns
- bool
True if this type has been registered, false if not.
Type Parameters
TType 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
containerIUnityContainerContainer to inspect.
nameToCheckstringName to check registration for.
Returns
- bool
True if this type/name pair has been registered, false if not.
Type Parameters
TType 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
containerIUnityContainerContainer to configure.
typeTypeType to register (may be an implemented interface instead of the actual type).
factoryFunc<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>lifetimeManagerIFactoryLifetimeManagerThe 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
containerIUnityContainerContainer to configure.
typeTypeType to register (may be an implemented interface instead of the actual type).
factoryFunc<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>lifetimeManagerIFactoryLifetimeManagerThe 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
containerIUnityContainerContainer to configure.
typeTypeType to register (may be an implemented interface instead of the actual type).
namestringName for registration.
factoryFunc<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>lifetimeManagerIFactoryLifetimeManagerThe 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
containerIUnityContainerContainer to configure.
typeTypeType to register (may be an implemented interface instead of the actual type).
namestringName for registration.
factoryFunc<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>lifetimeManagerIFactoryLifetimeManagerThe 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
containerIUnityContainerContainer to configure.
factoryFunc<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>lifetimeManagerIFactoryLifetimeManagerThe 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
TInterfaceType 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
containerIUnityContainerContainer to configure.
factoryFunc<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>lifetimeManagerIFactoryLifetimeManagerThe 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
TInterfaceType 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
containerIUnityContainerContainer to configure.
namestringName for registration.
factoryFunc<IUnityContainer, object>Predefined
to create typesFunc<IUnityContainer, object>lifetimeManagerIFactoryLifetimeManagerThe 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
TInterfaceType 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
containerIUnityContainerContainer to configure.
namestringName for registration.
factoryFunc<IUnityContainer, Type, string, object>Predefined
to create typesFunc<IUnityContainer, Type, string, object>lifetimeManagerIFactoryLifetimeManagerThe 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
TInterfaceType 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
containerIUnityContainerContainer to configure.
tTypeType of instance to register (may be an implemented interface instead of the full type).
instanceobjectObject 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
containerIUnityContainerContainer to configure.
tTypeType of instance to register (may be an implemented interface instead of the full type).
instanceobjectObject to returned.
lifetimeManagerIInstanceLifetimeManagerLifetimeManager 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
containerIUnityContainerContainer to configure.
tTypeType of instance to register (may be an implemented interface instead of the full type).
namestringName for registration.
instanceobjectObject 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
containerIUnityContainerContainer to configure.
namestringName for registration.
instanceTInterfaceObject to returned.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TInterfaceType 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
containerIUnityContainerContainer to configure.
namestringName for registration.
instanceTInterfaceObject to returned.
lifetimeManagerIInstanceLifetimeManagerLifetimeManager 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
TInterfaceType 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
containerIUnityContainerContainer to configure.
instanceTInterfaceObject to returned.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TInterfaceType 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
containerIUnityContainerContainer to configure.
instanceTInterfaceObject to returned.
lifetimeManagerIInstanceLifetimeManagerLifetimeManager 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
TInterfaceType 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
containerIUnityContainerContainer to configure.
tTypeThe Type to configure in the container.
namestringName to use for registration, null if a default registration.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
fromTypeType that will be requested.
toTypeType that will actually be returned.
namestringName to use for registration, null if a default registration.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
fromTypeType that will be requested.
toTypeType that will actually be returned.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
tTypeType this registration is for.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
namestringName that will be used to request the type.
injectionMembersInjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TThe 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
containerIUnityContainerContainer to configure.
injectionMembersInjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TType 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
containerIUnityContainerContainer to configure.
namestringName of this mapping.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
tTypeThe Type to configure in the container.
namestringName to use for registration, null if a default registration.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
tTypeThe Type to apply the
lifetimeManagerto.namestringName to use for registration, null if a default registration.
lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
fromTypeType that will be requested.
toTypeType that will actually be returned.
namestringName to use for registration, null if a default registration.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
fromTypeType that will be requested.
toTypeType that will actually be returned.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
fromTypeType that will be requested.
toTypeType that will actually be returned.
lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
tTypeType this registration is for.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
tTypeThe Type to apply the
lifetimeManagerto.lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
namestringName that will be used to request the type.
injectionMembersInjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TThe 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
containerIUnityContainerContainer to configure.
namestringName that will be used to request the type.
lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TThe type to apply the
lifetimeManagerto.
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
containerIUnityContainerContainer to configure.
injectionMembersInjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TType 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
containerIUnityContainerContainer to configure.
lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]Injection configuration objects.
Returns
- IUnityContainer
The IUnityContainer object that this method was called on.
Type Parameters
TThe type to apply the
lifetimeManagerto.
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
containerIUnityContainerContainer to configure.
namestringName of this mapping.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
namestringName to use for registration, null if a default registration.
lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to configure.
lifetimeManagerITypeLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
injectionMembersInjectionMember[]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
containerIUnityContainerContainer to resolve from.
tTypeType of object to get from the container.
overridesResolverOverride[]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
containerIUnityContainerContainer to resolve from.
typeTypeThe type requested.
resolverOverridesResolverOverride[]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
containerIUnityContainerContainer to resolve from.
resolverOverridesResolverOverride[]Any overrides for the resolve calls.
Returns
- IEnumerable<T>
Set of objects of type
T.
Type Parameters
TThe 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
containerIUnityContainerContainer to resolve from.
namestringName of the object to retrieve.
overridesResolverOverride[]Any overrides for the resolve call.
Returns
- T
The retrieved object.
Type Parameters
TType 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
containerIUnityContainerContainer to resolve from.
overridesResolverOverride[]Any overrides for the resolve call.
Returns
- T
The retrieved object.
Type Parameters
TType of object to get from the container.