I am trying to make an existing ASP.NET web form application more uniform, validated with some ASP.NET MVC objects, in particular HttpContextWrapper. I saw examples of its use, and they always create a new object. I parsed the source with Reflector and saw that everything it does keeps the past HttpContext. But I was wondering if it is safe to always create a new instance of HttpContextWrapper or follow a singleton pattern? Below is the class that I use in my application.
public static class AppHttpContext { public static HttpContextBase Current { get { return Getter(); } } public static void SetContext(Func<HttpContextBase> getter) { Getter = getter; } private static Func<HttpContextBase> Getter = () => new HttpContextWrapper(HttpContext.Current); }
And I use it like HttpContext.Current
AppHttpContext.Current.Session["blah"] = "something";
source share