Class SynchronizedLifetimeManager
Base class for Lifetime managers which need to synchronize calls to GetValue(ILifetimeContainer).
public abstract class SynchronizedLifetimeManager : LifetimeManager, IDisposable
- Inheritance
-
SynchronizedLifetimeManager
- Implements
- Derived
- Inherited Members
- Extension Methods
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
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.
public static int ResolveTimeout
Field Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
Standard Dispose pattern implementation.
protected virtual void Dispose(bool disposing)
Parameters
disposing
boolAlways true, since we don't have a finalizer.
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.
Recover()
A method that does whatever is needed to clean up as part of cleaning up after an exception.
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.
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
SynchronizedGetValue(ILifetimeContainer)
Performs the actual retrieval of a value from the backing store associated with this Lifetime policy.
protected abstract object SynchronizedGetValue(ILifetimeContainer container)
Parameters
container
ILifetimeContainerInstance 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 abstract void SynchronizedSetValue(object newValue, ILifetimeContainer container)
Parameters
newValue
objectThe object being stored.
container
ILifetimeContainerInstance of the lifetime's container
Remarks
This method is invoked by SetValue(object, ILifetimeContainer) before releasing its lock.
TryExit()
protected virtual void TryExit()
TryGetValue(ILifetimeContainer)
Retrieves a value from the backing store associated with this Lifetime policy.
public override object TryGetValue(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.
Remarks
This method does not block and does not acquire a lock on synchronization primitives.