Class SynchronizedLifetimeManager
Base class for Lifetime managers which need to synchronize calls to GetValue(ILifetimeContainer).
Inheritance
Implements
Inherited Members
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 SourceResolveTimeout
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 SourceDispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
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. |
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
| Improve this Doc View SourceRecover()
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.
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
| Improve this Doc View SourceSynchronizedGetValue(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.
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.
TryExit()
Declaration
protected virtual void TryExit()
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
Remarks
This method does not block and does not acquire a lock on synchronization primitives.