Interface IUnityContainerAsync
- Namespace
- Unity
- Assembly
- Unity.Abstractions.dll
Interface defining the behavior of the Unity dependency injection container.
[CLSCompliant(true)]
public interface IUnityContainerAsync : IDisposable
- Inherited Members
- Extension Methods
Properties
Parent
The parent of this container.
IUnityContainerAsync Parent { get; }
Property Value
- IUnityContainerAsync
The parent container, or null if this container doesn't have one.
Registrations
Lists all registrations available at this container.
IEnumerable<IContainerRegistration> Registrations { get; }
Property Value
Remarks
This collection contains all registrations from this container as well as from all predecessor containers if this is a child container. Registrations from child containers override registrations with same type and name from parent containers. The sort order of returned registrations is not guaranteed in any way.
Methods
CreateChildContainer()
Create a child container.
IUnityContainerAsync CreateChildContainer()
Returns
- IUnityContainerAsync
The new child container.
Remarks
A child container shares the parent's configuration, but can be configured with different settings or lifetime.
IsRegistered(Type, string)
This is a fast way to check if type is registered with container
bool IsRegistered(Type type, string name)
Parameters
Returns
Remarks
This method is quite fast. Although it is not free in terms of time spent, it uses the same algorithm the container employs to obtain registrations and wastes very little time.
RegisterFactory(IEnumerable<Type>, string, Func<IUnityContainer, Type, string, object>, IFactoryLifetimeManager)
Register Type factory with the container
Task RegisterFactory(IEnumerable<Type> interfaces, string name, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager)
Parameters
interfaces
IEnumerable<Type>Collection of interfaces that
factory
exposes to containername
stringName for registration
factory
Func<IUnityContainer, Type, string, object>lifetimeManager
IFactoryLifetimeManagerThe LifetimeManager that controls the lifetime of the returned instance.
Returns
RegisterInstance(IEnumerable<Type>, string, object, IInstanceLifetimeManager)
Register an instance with the container.
Task RegisterInstance(IEnumerable<Type> interfaces, string name, object instance, IInstanceLifetimeManager lifetimeManager)
Parameters
interfaces
IEnumerable<Type>Collection of interfaces that
instance
exposes to containername
stringName for registration
instance
objectObject to be registered
lifetimeManager
IInstanceLifetimeManagerLifetimeManager manager that controls how this instance will be managed by the container. Following are the only valid options: ContainerControlledLifetimeManager, SingletonLifetimeManager, ExternallyControlledLifetimeManager
Returns
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.
RegisterType(IEnumerable<Type>, Type, string, ITypeLifetimeManager, params InjectionMember[])
Registers implementation type via provided collection of it's interfaces.
Task RegisterType(IEnumerable<Type> interfaces, Type type, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
interfaces
IEnumerable<Type>Collection of interfaces that
type
exposes to containertype
TypeType that will be used to instantiate object.
name
stringName of the registration
lifetimeManager
ITypeLifetimeManagerLifetime manager that will be responsible for managing created object's lifetime.
injectionMembers
InjectionMember[]Injection configuration objects.
Returns
Remarks
This method allows creation of single registration for multiple interfaces the object of type might be exposing. Registrations created with this method are self contained and will never 'Map' to other registrations. In other words this registration will always create build plan and resolve new objects through it.
Resolve(Type, Regex, params ResolverOverride[])
Resolve an instance of the requested type from the container.
ValueTask<IEnumerable<object>> Resolve(Type type, Regex regex, params ResolverOverride[] overrides)
Parameters
type
TypeType of object to get typeFrom the container.
regex
RegexPattern to match names to. Only these with successful Regex.IsMatch(string name) will be resolved
overrides
ResolverOverride[]Any overrides for the resolve call.
Returns
- ValueTask<IEnumerable<object>>
The retrieved object.
ResolveAsync(Type, string, params ResolverOverride[])
Resolve an instance of the requested type from the container.
ValueTask<object> ResolveAsync(Type type, string name, params ResolverOverride[] overrides)
Parameters
type
TypeType of object to get typeFrom the container.
name
stringName of the object to retrieve.
overrides
ResolverOverride[]Any overrides for the resolve call.