Class PerThreadLifetimeManager
A LifetimeManager that creates a new instance of the registered Type once per each thread.
public class PerThreadLifetimeManager : LifetimeManager, IFactoryLifetimeManager, ITypeLifetimeManager
- Inheritance
-
PerThreadLifetimeManager
- Implements
- Inherited Members
- Extension Methods
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
GetValue(ILifetimeContainer)
Retrieves a value from the backing store associated with this Lifetime policy.
public override object GetValue(ILifetimeContainer container = null)
Parameters
container
ILifetimeContainerThe 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 override LifetimeManager OnCreateLifetimeManager()
Returns
- LifetimeManager
A new instance of the same lifetime manager of appropriate type
SetValue(object, ILifetimeContainer)
Stores the given value into backing store for retrieval later.
public override void SetValue(object newValue, ILifetimeContainer container = null)
Parameters
newValue
objectThe object being stored.
container
ILifetimeContainerThe container this lifetime is associated with
ToString()
This method provides human readable representation of the lifetime
public override string ToString()
Returns
- string
Name of the lifetime