Show / Hide Table of Contents

Class PerThreadLifetimeManager

A LifetimeManager that creates a new instance of the registered Type once per each thread.

Inheritance
Object
LifetimeManager
PerThreadLifetimeManager
Implements
IFactoryLifetimeManager
ITypeLifetimeManager
Inherited Members
LifetimeManager.NoValue
LifetimeManager.InUse
LifetimeManager.TryGet
LifetimeManager.Get
LifetimeManager.Set
LifetimeManager.TryGetValue(ILifetimeContainer)
LifetimeManager.RemoveValue(ILifetimeContainer)
LifetimeManager.CreateLifetimePolicy()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Namespace: Unity.Lifetime
Assembly: Unity.Abstractions.dll
Syntax
public class PerThreadLifetimeManager : LifetimeManager, IFactoryLifetimeManager, ITypeLifetimeManager
Remarks

Per thread lifetime means a new instance of the registered Type will be created once per each thread. In other words, if a Resolve{T}() method is called on a thread the first time, it will return a new object. Each subsequent call to Resolve{T}(), or when the dependency mechanism injects instances of the type into other classes on the same thread, the container will return the same object.

This LifetimeManager does not dispose the instances it holds.

Methods

| Improve this Doc View Source

GetValue(ILifetimeContainer)

Retrieves a value from the backing store associated with this Lifetime policy.

Declaration
public override 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.

Overrides
LifetimeManager.GetValue(ILifetimeContainer)
| Improve this Doc View Source

OnCreateLifetimeManager()

Implementation of CreateLifetimePolicy() policy.

Declaration
protected override LifetimeManager OnCreateLifetimeManager()
Returns
Type Description
LifetimeManager

A new instance of the same lifetime manager of appropriate type

Overrides
LifetimeManager.OnCreateLifetimeManager()
| Improve this Doc View Source

SetValue(Object, ILifetimeContainer)

Stores the given value into backing store for retrieval later.

Declaration
public override 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

Overrides
LifetimeManager.SetValue(Object, ILifetimeContainer)
| Improve this Doc View Source

ToString()

This method provides human readable representation of the lifetime

Declaration
public override string ToString()
Returns
Type Description
String

Name of the lifetime

Overrides
Object.ToString()

Implements

IFactoryLifetimeManager
ITypeLifetimeManager

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