we have a class with a dependency to the HttpContext.
We’ve implemented it like this:
public SiteVariation() : this(new HttpContextWrapper(HttpContext.Current))
{
}
public SiteVariation(HttpContextBase context)
{}
Now what i want to do is to instantiate the SiteVariation class via Unity, so we can create one constructor.
But i do not know how to configure this new HttpContextWrapper(HttpContext.Current)) in Unity in the config way.
ps
this is the config way we use
<type type="Web.SaveRequest.ISaveRequestHelper, Common" mapTo="Web.SaveRequest.SaveRequestHelper, Common" />
I wouldn’t take a dependency on
HttpContextBasedirectly. I would instead create a wrapper around it, and use the bits you need:then the implementation:
This way, your class now just relies on a wrapper, and doesn’t need the actual HttpContext to function. Makes it much easier to inject, and much easier to test: