Microsoft has already built large wrappers and abstractions around the HttpContext , HttpRequest and HttpResponse that are included in .NET, so I will definitely use them directly, rather than wrapping them myself.
You can configure Unity for the HttpContextBase with an InjectionFactory , for example:
var container = new UnityContainer(); container.RegisterType<HttpContextBase>(new InjectionFactory(_ => new HttpContextWrapper(HttpContext.Current)));
Also, if you need HttpRequestBase (which I usually use the most) and HttpResponseBase , you can register them as follows:
container.RegisterType<HttpRequestBase>(new InjectionFactory(_ => new HttpRequestWrapper(HttpContext.Current.Request))); container.RegisterType<HttpResponseBase>(new InjectionFactory(_ => new HttpResponseWrapper(HttpContext.Current.Response)));
You can easily make fun of HttpContextBase , HttpRequestBase and HttpResponseBase in unit tests without custom wrappers.
Christian fredh
source share