I consider that Dependency Injection (DI) is a very helpful pattern, I love to use it in order to reduce the coupling in my code and it helps me when writing unit tests. But sometimes the code depends on objects that are difficult or impossible to mock.
The HttpContext class of the ASP .NET MVC framework is one example of this kind of object.
I created the following Controller and View as examples:
publicclass IndexController : Controller {[HttpGet]public ActionResult Index(){string[] languages = HttpContext.Request.UserLanguages;return View(model:languages);}}
@model string[]
@{
Layout = null;
}
<!--DOCTYPE html>
<html><head><metaname="viewport"content="width=device-width"/><title>Index</title></head><body>
View original post 759 more words