title: How to inject HttpContextBase using Autofac in ASP.NET MVC 4
body: <p>I am using <code>ASP.MVC 4</code> and <code>Autofac</code>.</p>
  
  <p>I have registered the following in my <code>global.asax.cs</code> file:</p>
  
  <pre><code>ContainerBuilder builder = new ContainerBuilder();
  
  builder.Register(c =&gt; c.Resolve&lt;HttpContextBase&gt;().Request)
       .As&lt;HttpRequestBase&gt;()
       .InstancePerHttpRequest();
  builder.Register(c =&gt; c.Resolve&lt;HttpContextBase&gt;().Response)
       .As&lt;HttpResponseBase&gt;()
       .InstancePerHttpRequest();
  builder.Register(c =&gt; c.Resolve&lt;HttpContextBase&gt;().Server)
       .As&lt;HttpServerUtilityBase&gt;()
       .InstancePerHttpRequest();
  builder.Register(c =&gt; c.Resolve&lt;HttpContextBase&gt;().Session)
       .As&lt;HttpSessionStateBase&gt;()
       .InstancePerHttpRequest();
  
  builder.RegisterControllers(Assembly.GetExecutingAssembly());
  
  builder.RegisterType&lt;WebWorkContext&gt;().As&lt;IWorkContext&gt;().InstancePerHttpRequest();
  </code></pre>
  
  <p>In my Home controller I have this (just for testing purposes):</p>
  
  <pre><code>private readonly HttpContextBase httpContext;
  
  public HomeController(HttpContextBase httpContext)
  {
       this.httpContext = httpContext;
  }
  </code></pre>
  
  <p>I used the exact same code with an ASP.NET MVC 3 project and it worked fine.  Now in this project I am getting errors.  Not sure why?  The error that I am getting is:</p>
  
  <p><strong>None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'MyProject.Web.Controllers.HomeController' can be invoked with the available services and parameters:  Cannot resolve parameter 'System.Web.HttpContextBase httpContext' of constructor 'Void .ctor(System.Web.HttpContextBase)'.     at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable<code>1 parameters)     at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable</code>1 parameters)     at Autofac.Core.Resolving.InstanceLookup.Execute()     at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable<code>1 parameters)     at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable</code>1 parameters)     at Autofac.Core.Registration.ExternalRegistrySource.&lt;</strong></p>
  
  <p>I'm not too sure why this won't work?  Do I need to do things differently in ASP.NET 4?</p>
  
  <p>I have a separate project in which I also want to inject <code>HttpContextBase</code> and I am getting the same error.</p>