Class InstanceLifetime
- Namespace
- Unity
- Assembly
- Unity.Abstractions.dll
public static class InstanceLifetime
- Inheritance
-
InstanceLifetime
- Inherited Members
Properties
External
This lifetime stores a weak reference to an instance and returns an instance while it is available.
public static IInstanceLifetimeManager External { get; }
Property Value
- IInstanceLifetimeManager
A new instance of a ExternallyControlledLifetimeManager lifetime manager.
Remarks
Container gets a hold of a weak reference to the object and as long as the object still exists and has not been garbage collected the container will return the object when requested.
If the object went out of scope and has been garbage collected the container will return NoValue.
This lifetime manager does not dispose an object when container is disposed
PerContainer
Unity returns the same instance each time the Resolve(...) method is called or when the dependency mechanism injects the instance into other classes.
public static IInstanceLifetimeManager PerContainer { get; }
Property Value
- IInstanceLifetimeManager
A new instance of a ContainerControlledLifetimeManager object.
Remarks
Per Container lifetime allows a registration of an existing or resolved object as a scoped singleton in the container it was created or registered. In other words this instance is unique within the container it war registered with. Child or parent containers could have their own instances registered for the same contract.
Singleton
Singleton lifetime creates globally unique singleton. Any Unity container tree (parent and all the children) is guaranteed to have only one global singleton for the registered type.
public static IInstanceLifetimeManager Singleton { get; }
Property Value
- IInstanceLifetimeManager
A new instance of a SingletonLifetimeManager object.
Remarks
Registering a type with singleton lifetime always places the registration at the root of the container tree and makes it globally available for all the children of that container. It does not matter if registration takes places at the root of child container the destination is always the root node.
Repeating the registration on any of the child nodes with singleton lifetime will always override the root registration.