Class LifetimeManager
Base class for all lifetime managers - classes that control how and when instances are created by the Unity container.
public abstract class LifetimeManager
- Inheritance
-
LifetimeManager
- Derived
- Inherited Members
- Extension Methods
Constructors
LifetimeManager()
public LifetimeManager()
Fields
NoValue
This value represents Invalid Value. Lifetime manager must return this unless value is set with a valid object. Null is a value and is not equal to NoValue
public static readonly object NoValue
Field Value
Properties
Get
public virtual Func<ILifetimeContainer, object> Get { get; protected set; }
Property Value
InUse
A bool indicating if this manager is being used in one of the registrations.
public virtual bool InUse { get; set; }
Property Value
- bool
True is this instance already in use, False otherwise.
Remarks
The Unity container requires that each registration used its own, unique lifetime manager. This property is being used to track that condition.
Set
public virtual Action<object, ILifetimeContainer> Set { get; protected set; }
Property Value
TryGet
public virtual Func<ILifetimeContainer, object> TryGet { get; protected set; }
Property Value
Methods
CreateLifetimePolicy()
Creates a new lifetime manager of the same type as this Lifetime Manager
public LifetimeManager CreateLifetimePolicy()
Returns
- LifetimeManager
A new instance of the appropriate lifetime manager
GetValue(ILifetimeContainer)
Retrieves a value from the backing store associated with this Lifetime policy.
public virtual object GetValue(ILifetimeContainer container = null)
Parameters
container
ILifetimeContainerThe container this lifetime is associated with
Returns
- object
the object desired, or null if no such object is currently stored.
OnCreateLifetimeManager()
Implementation of CreateLifetimePolicy() policy.
protected abstract LifetimeManager OnCreateLifetimeManager()
Returns
- LifetimeManager
A new instance of the same lifetime manager of appropriate type
RemoveValue(ILifetimeContainer)
Remove the given object from backing store.
public virtual void RemoveValue(ILifetimeContainer container = null)
Parameters
container
ILifetimeContainerThe container this lifetime belongs to
SetValue(object, ILifetimeContainer)
Stores the given value into backing store for retrieval later.
public virtual void SetValue(object newValue, ILifetimeContainer container = null)
Parameters
newValue
objectThe object being stored.
container
ILifetimeContainerThe container this lifetime is associated with
TryGetValue(ILifetimeContainer)
Retrieves a value from the backing store associated with this Lifetime policy.
public virtual object TryGetValue(ILifetimeContainer container = null)
Parameters
container
ILifetimeContainerThe container this lifetime is associated with
Returns
- object
the object desired, or null if no such object is currently stored.
Remarks
This method does not block and does not acquire a lock on synchronization primitives.