Show / Hide Table of Contents

Class SynchronizedLifetimeManager

Base class for Lifetime managers which need to synchronize calls to GetValue(ILifetimeContainer).

Inheritance
Object
LifetimeManager
SynchronizedLifetimeManager
ContainerControlledLifetimeManager
ExternallyControlledLifetimeManager
HierarchicalLifetimeManager
Implements
IDisposable
Inherited Members
LifetimeManager.NoValue
LifetimeManager.InUse
LifetimeManager.TryGet
LifetimeManager.Get
LifetimeManager.Set
LifetimeManager.RemoveValue(ILifetimeContainer)
LifetimeManager.CreateLifetimePolicy()
LifetimeManager.OnCreateLifetimeManager()
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 SynchronizedLifetimeManager : LifetimeManager, IDisposable
Remarks

The purpose of this class is to provide a basic implementation of the lifetime manager synchronization pattern.

Calls to the GetValue(ILifetimeContainer) method of a SynchronizedLifetimeManager instance acquire a lock, and if the instance has not been initialized with a value yet the lock will only be released when such an initialization takes place by calling the SetValue(Object, ILifetimeContainer) method or if the build request which resulted in the call to the GetValue method fails.

Fields

| Improve this Doc View Source

ResolveTimeout

This field controls how long the monitor will wait to enter the lock. It is Infinite by default or number of milliseconds from 0 to 2147483647.

Declaration
public static int ResolveTimeout
Field Value
Type Description
Int32

Methods

| Improve this Doc View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()
| Improve this Doc View Source

Dispose(Boolean)

Standard Dispose pattern implementation.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

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

| 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

Recover()

A method that does whatever is needed to clean up as part of cleaning up after an exception.

Declaration
public void Recover()
Remarks

Don't do anything that could throw in this method, it will cause later recover operations to get skipped and play real havoc with the stack trace.

| 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

SynchronizedGetValue(ILifetimeContainer)

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

Declaration
protected abstract object SynchronizedGetValue(ILifetimeContainer container)
Parameters
Type Name Description
ILifetimeContainer container

Instance of the lifetime's container

Returns
Type Description
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.

| Improve this Doc View Source

SynchronizedSetValue(Object, ILifetimeContainer)

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

Declaration
protected abstract void SynchronizedSetValue(object newValue, ILifetimeContainer container)
Parameters
Type Name Description
Object newValue

The object being stored.

ILifetimeContainer container

Instance of the lifetime's container

Remarks

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

| Improve this Doc View Source

TryExit()

Declaration
protected virtual void TryExit()
| Improve this Doc View Source

TryGetValue(ILifetimeContainer)

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

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

Overrides
LifetimeManager.TryGetValue(ILifetimeContainer)
Remarks

This method does not block and does not acquire a lock on synchronization primitives.

Implements

System.IDisposable

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