Table of Contents

Class LifetimeManager

Namespace
Unity.Lifetime
Assembly
Unity.Abstractions.dll

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

object

Properties

Get

public virtual Func<ILifetimeContainer, object> Get { get; protected set; }

Property Value

Func<ILifetimeContainer, object>

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

Action<object, ILifetimeContainer>

TryGet

public virtual Func<ILifetimeContainer, object> TryGet { get; protected set; }

Property Value

Func<ILifetimeContainer, object>

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 ILifetimeContainer

The 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 ILifetimeContainer

The 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 object

The object being stored.

container ILifetimeContainer

The 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 ILifetimeContainer

The 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.