I am trying to work out a way to pass the current web http context to a service class (or initialize the class with a link to it). I am doing this to distract the rest of the application from having to know anything about the http context.
I also want the service to be checked using TDD, possibly using one of the Mockable frameworks. Therefore, it would be preferable to use an interface rather than the actual class.
An example of what I would like to achieve:
class WebInstanceService
{
private IHttpContext _Context;
public WebInstanceService( ... , IHttpContext HttpContext )
{
....
_Context = HttpContext;
}
public string GetInstanceVariable(string VariableName)
{
return _Context.Current.Session[VariableName];
}
}
One of the main problems I have is the lack of IHttpContext, the .net http context is a subclass of an abstract class that cannot be mocked (easy?).
, , .
static , Context , i.e.
public static string GetInstanceVariable(string VariableName, HttpContext Context)
{ ... }
, HttpContext, , , , -, , , - - .
- , , tdd. ?