Created
August 5, 2016 16:32
-
-
Save cathode/532926e5fff089482a9420b33fe2b4d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
/// Provides static properties that return context or request-specific values. | |
/// </summary> | |
public static class Current | |
{ | |
/// <summary> | |
/// Gets the <see cref="IbisDB"/> instance used for the lifetime of the current web request. | |
/// </summary> | |
public static IbisDB Context | |
{ | |
get | |
{ | |
if (!HttpContext.Current.Items.Contains(typeof(IbisDB).ToString())) | |
{ | |
var db = new IbisDB(); | |
HttpContext.Current.Items.Add(typeof(IbisDB).ToString(), db); | |
HttpContext.Current.AddOnRequestCompleted(a => | |
{ | |
db.SaveChanges(); | |
//db.Dispose(); | |
}); | |
} | |
return HttpContext.Current.Items[typeof(IbisDB).ToString()] as IbisDB; | |
} | |
} | |
public static Session Session | |
{ | |
get | |
{ | |
return HttpContext.Current.Items[typeof(Session).ToString()] as Session; | |
} | |
internal set | |
{ | |
HttpContext.Current.Items.Add(typeof(Session).ToString(), value); | |
} | |
} | |
public static Identity Identity | |
{ | |
get | |
{ | |
return HttpContext.Current.User.Identity as Identity; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment