I would create a ModelBinder that understands CookieData and how to get it from the Request object. I am afraid that the unit test code is needed to make the constructor happy. If you accept it as a parameter for the controller using the Binder module, you can avoid this overhead.
public class SomeController : Controller {
The answer to why it does not work in the constructor is that the controller was not initialized with the ControllerContext at this point.
public HttpContextBase HttpContext { get { return ControllerContext == null ? null : ControllerContext.HttpContext; } }
If you really want to do this in the constructor (don't use), use HttpContext.Request instead of a wrapper. But by doing this, you will make your code unstable, and your alignment will decrease by 3 points.
source share