Last active
July 10, 2016 12:07
-
-
Save dejanvasic85/59184570ef7a2119c4993a839dceea37 to your computer and use it in GitHub Desktop.
Custom Unity lifetime manager
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
public class SessionLifetimeManager<T> : Microsoft.Practices.Unity.LifetimeManager | |
{ | |
private string key; | |
public SessionLifetimeManager() | |
{ | |
this.key = typeof(T).Name; | |
} | |
/// <summary> | |
/// Retrieve a value from the backing store associated with this Lifetime policy. | |
/// </summary> | |
/// <returns> | |
/// the object desired, or null if no such object is currently stored. | |
/// </returns> | |
public override object GetValue() | |
{ | |
return HttpContext.Current.Session[this.key]; | |
} | |
/// <summary> | |
/// Stores the given value into backing store for retrieval later. | |
/// </summary> | |
/// <param name="newValue">The object being stored.</param> | |
public override void SetValue(object newValue) | |
{ | |
HttpContext.Current.Session[this.key] = newValue; | |
} | |
/// <summary> | |
/// Remove the given object from backing store. | |
/// </summary> | |
public override void RemoveValue() | |
{ | |
} | |
} |
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
public interface ISession{ | |
string Get(string key); | |
void Set(string key, string value); | |
} | |
public class SimpleSessionStore : ISession{ | |
public string Get(string key){ | |
return HttpContext.Current.Session[key]; | |
} | |
public void Set(string key, string value){ | |
HttpContext.Current.Session[key] = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment