Show / Hide Table of Contents

Class LifetimeManager

Base class for all lifetime managers - classes that control how and when instances are created by the Unity container.

Inheritance
Object
LifetimeManager
ContainerControlledTransientManager
PerResolveLifetimeManager
PerThreadLifetimeManager
SynchronizedLifetimeManager
TransientLifetimeManager
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Unity.Lifetime
Assembly: Unity.Abstractions.dll
Syntax
public abstract class LifetimeManager

Constructors

| Improve this Doc View Source

LifetimeManager()

Declaration
public LifetimeManager()

Fields

| Improve this Doc View Source

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

Declaration
public static readonly object NoValue
Field Value
Type Description
Object

Properties

| Improve this Doc View Source

Get

Declaration
public virtual Func<ILifetimeContainer, object> Get { get; protected set; }
Property Value
Type Description
Func<ILifetimeContainer, Object>
| Improve this Doc View Source

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.

| Improve this Doc View Source

Set

Declaration
public virtual Action<object, ILifetimeContainer> Set { get; protected set; }
Property Value
Type Description
Action<Object, ILifetimeContainer>
| Improve this Doc View Source

TryGet

Declaration
public virtual Func<ILifetimeContainer, object> TryGet { get; protected set; }
Property Value
Type Description
Func<ILifetimeContainer, Object>

Methods

| Improve this Doc View Source

CreateLifetimePolicy()

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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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.

Extension Methods

InjectionMatching.Matches(Object, Type)
InjectionMatching.MatchesObject(Object, Type)
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2020 .NET Foundation and Contributors. All Rights Reserved