Interface IUnityContainerAsync
Interface defining the behavior of the Unity dependency injection container.
Inherited Members
Namespace: Unity
Assembly: Unity.Abstractions.dll
Syntax
[CLSCompliant(true)]
public interface IUnityContainerAsync : IDisposable
Properties
| Improve this Doc View SourceParent
The parent of this container.
Declaration
IUnityContainerAsync Parent { get; }
Property Value
Type | Description |
---|---|
IUnityContainerAsync | The parent container, or null if this container doesn't have one. |
Registrations
Lists all registrations available at this container.
Declaration
IEnumerable<IContainerRegistration> Registrations { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IContainerRegistration> |
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
| Improve this Doc View SourceCreateChildContainer()
Create a child container.
Declaration
IUnityContainerAsync CreateChildContainer()
Returns
Type | Description |
---|---|
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
Declaration
bool IsRegistered(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type to look for |
String | name | Name of the registration |
Returns
Type | Description |
---|---|
Boolean |
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
Declaration
Task RegisterFactory(IEnumerable<Type> interfaces, string name, Func<IUnityContainer, Type, string, object> factory, IFactoryLifetimeManager lifetimeManager)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Type> | interfaces | Collection of interfaces that |
String | name | Name for registration |
Func<IUnityContainer, Type, String, Object> | factory | |
IFactoryLifetimeManager | lifetimeManager | The LifetimeManager that controls the lifetime of the returned instance. |
Returns
Type | Description |
---|---|
Task | Returns Task indicating when registration is done |
RegisterInstance(IEnumerable<Type>, String, Object, IInstanceLifetimeManager)
Register an instance with the container.
Declaration
Task RegisterInstance(IEnumerable<Type> interfaces, string name, object instance, IInstanceLifetimeManager lifetimeManager)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Type> | interfaces | Collection of interfaces that |
String | name | Name for registration |
Object | instance | Object to be registered |
IInstanceLifetimeManager | lifetimeManager | LifetimeManager manager that controls how this instance will be managed by the container. Following are the only valid options: ContainerControlledLifetimeManager, SingletonLifetimeManager, ExternallyControlledLifetimeManager |
Returns
Type | Description |
---|---|
Task | Returns Task indicating when registration is done |
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, InjectionMember[])
Registers implementation type via provided collection of it's interfaces.
Declaration
Task RegisterType(IEnumerable<Type> interfaces, Type type, string name, ITypeLifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Type> | interfaces | Collection of interfaces that |
Type | type | Type that will be used to instantiate object. |
String | name | Name of the registration |
ITypeLifetimeManager | lifetimeManager | Lifetime manager that will be responsible for managing created object's lifetime. |
InjectionMember[] | injectionMembers | Injection configuration objects. |
Returns
Type | Description |
---|---|
Task | Returns Task indicating when registration is done |
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, ResolverOverride[])
Resolve an instance of the requested type from the container.
Declaration
ValueTask<IEnumerable<object>> Resolve(Type type, Regex regex, params ResolverOverride[] overrides)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of object to get typeFrom the container. |
Regex | regex | Pattern to match names to. Only these with successful
|
ResolverOverride[] | overrides | Any overrides for the resolve call. |
Returns
Type | Description |
---|---|
ValueTask<IEnumerable<Object>> | The retrieved object. |
ResolveAsync(Type, String, ResolverOverride[])
Resolve an instance of the requested type from the container.
Declaration
ValueTask<object> ResolveAsync(Type type, string name, params ResolverOverride[] overrides)
Parameters
Type | Name | Description |
---|---|---|
Type | type | Type of object to get typeFrom the container. |
String | name | Name of the object to retrieve. |
ResolverOverride[] | overrides | Any overrides for the resolve call. |
Returns
Type | Description |
---|---|
ValueTask<Object> | The retrieved object. |