How to inject HttpContextBase using Autofac in ASP.NET MVC 4
Thanks to nemesv
.
I ended up replacing:
builder.Register(c => c.Resolve<HttpContextBase>().Request) .As<HttpRequestBase>() .InstancePerHttpRequest();builder.Register(c => c.Resolve<HttpContextBase>().Response) .As<HttpResponseBase>() .InstancePerHttpRequest();builder.Register(c => c.Resolve<HttpContextBase>().Server) .As<HttpServerUtilityBase>() .InstancePerHttpRequest();builder.Register(c => c.Resolve<HttpContextBase>().Session) .As<HttpSessionStateBase>() .InstancePerHttpRequest();
...with just:
builder.RegisterModule(new AutofacWebTypesModule());
It works now. Not sure what the difference is but the code in the module looks exactly the same as mine above.