Table of Contents

Class HierarchicalLifetimeManager

Namespace
Unity.Lifetime
Assembly
Unity.Abstractions.dll

A special lifetime manager which works like ContainerControlledLifetimeManager, except that in the presence of child containers, each child gets it's own instance of the object, instead of sharing one in the common parent.

public class HierarchicalLifetimeManager : SynchronizedLifetimeManager, IDisposable, IFactoryLifetimeManager, ITypeLifetimeManager
Inheritance
HierarchicalLifetimeManager
Implements
Inherited Members
Extension Methods

Remarks

The Unity container allows creating hierarchies of child containers. This lifetime creates local singleton for each level of the hierarchy. So, when you resolve a type and this container does not have an instance of that type, the container will create new instance. Next type the type is resolved the same instance will be returned.

If a child container is created and requested to resolve the type, the child container will create a new instance and store it for subsequent resolutions. Next time the child container requested to resolve the type, it will return stored instance.

If you have multiple children, each will resolve its own instance.

Methods

Dispose(bool)

Standard Dispose pattern implementation.

protected override void Dispose(bool disposing)

Parameters

disposing bool

Always true, since we don't have a finalizer.

OnCreateLifetimeManager()

Implementation of CreateLifetimePolicy() policy.

protected override 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 override void RemoveValue(ILifetimeContainer container = null)

Parameters

container ILifetimeContainer

The container this lifetime belongs to

SynchronizedGetValue(ILifetimeContainer)

Performs the actual retrieval of a value from the backing store associated with this Lifetime policy.

protected override object SynchronizedGetValue(ILifetimeContainer container = null)

Parameters

container ILifetimeContainer

Instance of the lifetime's container

Returns

object

the object desired, or null if no such object is currently stored.

Remarks

This method is invoked by GetValue(ILifetimeContainer) after it has acquired its lock.

SynchronizedSetValue(object, ILifetimeContainer)

Performs the actual storage of the given value into backing store for retrieval later.

protected override void SynchronizedSetValue(object newValue, ILifetimeContainer container = null)

Parameters

newValue object

The object being stored.

container ILifetimeContainer

Instance of the lifetime's container

Remarks

This method is invoked by SetValue(object, ILifetimeContainer) before releasing its lock.

ToString()

This method provides human readable representation of the lifetime

public override string ToString()

Returns

string

Name of the lifetime