Class LifetimeManager
Base class for all lifetime managers - classes that control how and when instances are created by the Unity container.
Inheritance
Inherited Members
Namespace: Unity.Lifetime
Assembly: Unity.Abstractions.dll
Syntax
public abstract class LifetimeManager
Constructors
| Improve this Doc View SourceLifetimeManager()
Declaration
public LifetimeManager()
Fields
| Improve this Doc View SourceNoValue
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
Declaration
public static readonly object NoValue
Field Value
Type | Description |
---|---|
Object |
Properties
| Improve this Doc View SourceGet
Declaration
public virtual Func<ILifetimeContainer, object> Get { get; protected set; }
Property Value
Type | Description |
---|---|
Func<ILifetimeContainer, Object> |
InUse
A Boolean indicating if this manager is being used in one of the registrations.
Declaration
public virtual bool InUse { get; set; }
Property Value
Type | Description |
---|---|
Boolean | 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
Declaration
public virtual Action<object, ILifetimeContainer> Set { get; protected set; }
Property Value
Type | Description |
---|---|
Action<Object, ILifetimeContainer> |
TryGet
Declaration
public virtual Func<ILifetimeContainer, object> TryGet { get; protected set; }
Property Value
Type | Description |
---|---|
Func<ILifetimeContainer, Object> |
Methods
| Improve this Doc View SourceCreateLifetimePolicy()
Creates a new lifetime manager of the same type as this Lifetime Manager
Declaration
public LifetimeManager CreateLifetimePolicy()
Returns
Type | Description |
---|---|
LifetimeManager | A new instance of the appropriate lifetime manager |
GetValue(ILifetimeContainer)
Retrieves a value from the backing store associated with this Lifetime policy.
Declaration
public virtual object GetValue(ILifetimeContainer container = null)
Parameters
Type | Name | Description |
---|---|---|
ILifetimeContainer | container | The container this lifetime is associated with |
Returns
Type | Description |
---|---|
Object | the object desired, or null if no such object is currently stored. |
OnCreateLifetimeManager()
Implementation of CreateLifetimePolicy() policy.
Declaration
protected abstract LifetimeManager OnCreateLifetimeManager()
Returns
Type | Description |
---|---|
LifetimeManager | A new instance of the same lifetime manager of appropriate type |
RemoveValue(ILifetimeContainer)
Remove the given object from backing store.
Declaration
public virtual void RemoveValue(ILifetimeContainer container = null)
Parameters
Type | Name | Description |
---|---|---|
ILifetimeContainer | container | The container this lifetime belongs to |
SetValue(Object, ILifetimeContainer)
Stores the given value into backing store for retrieval later.
Declaration
public virtual void SetValue(object newValue, ILifetimeContainer container = null)
Parameters
Type | Name | Description |
---|---|---|
Object | newValue | The object being stored. |
ILifetimeContainer | container | The container this lifetime is associated with |
TryGetValue(ILifetimeContainer)
Retrieves a value from the backing store associated with this Lifetime policy.
Declaration
public virtual object TryGetValue(ILifetimeContainer container = null)
Parameters
Type | Name | Description |
---|---|---|
ILifetimeContainer | container | The container this lifetime is associated with |
Returns
Type | Description |
---|---|
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.