Created
October 23, 2013 14:19
-
-
Save glikoz/7119699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Represents a lifetime manager for request base life time management | |
/// </summary> | |
public class PerRequestLifetimeManager : LifetimeManager | |
{ | |
#region Members | |
private LifetimeManager _WrappedLifetimeManager; | |
#endregion | |
#region Public Methods | |
/// <summary> | |
/// Gets value | |
/// </summary> | |
/// <returns></returns> | |
public override object GetValue() | |
{ | |
EnsureLifetimeManager(); | |
return _WrappedLifetimeManager.GetValue(); | |
} | |
/// <summary> | |
/// Remove value | |
/// </summary> | |
public override void RemoveValue() | |
{ | |
EnsureLifetimeManager(); | |
_WrappedLifetimeManager.RemoveValue(); | |
} | |
/// <summary> | |
/// Sets value | |
/// </summary> | |
/// <param name="newValue"></param> | |
public override void SetValue(object newValue) | |
{ | |
EnsureLifetimeManager(); | |
_WrappedLifetimeManager.SetValue(newValue); | |
} | |
#endregion | |
#region Private Methods | |
/// <summary> | |
/// Ensures that lifetime manager which is wrapped is created | |
/// </summary> | |
private void EnsureLifetimeManager() | |
{ | |
if (_WrappedLifetimeManager == null) | |
{ | |
if (HttpContext.Current != null) | |
{ | |
_WrappedLifetimeManager = new PerWebRequestLifetimeManager(); | |
} | |
else if (OperationContext.Current != null) | |
{ | |
_WrappedLifetimeManager = new PerWCFRequestLifetimeManager(); | |
} | |
else | |
{ | |
_WrappedLifetimeManager = new PerCallContextLifetimeManager(); | |
} | |
} | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment