title: Parameter not registered when using Simple Injector to inject into an MVC Controller Constructor
body: <p>I'm have what seems to be a very basic problem using Simple Injector to inject dependencies into an MVC Controller.  I am new to using Simple Injector having used StructureMap previously.</p>
  
  <p>The version of MVC is 4.5 and it is the latest version of Simple Injector installed from NuGet. </p>
  
  <p>The error I am getting when viewing the /Index view of the HomeController is:</p>
  
  <blockquote>
    <p>The constructor of the type HomeController contains the parameter of type IContext with name 'context' that is not registered. Please ensure IContext is registered in the container, or change the constructor of HomeController. </p>
  </blockquote>
  
  <p>The controller is as so:</p>
  
  <pre><code>public class HomeController : Controller
  {
      public HomeController(IContext context) { }
  
      public ActionResult Index() { }
  }
  </code></pre>
  
  <p>The IContext is just a simple interface:</p>
  
  <pre><code>public interface IContext
  {
  }
  </code></pre>
  
  <p>And the concrete IContext implementation also simple and is just a wrapper for a regular DbContext.</p>
  
  <pre><code>public class DbContext : System.Data.Entity.DbContext, IContext
  { 
  
  }
  </code></pre>
  
  <p>For info, the IContext interface lives in a different VS Project/Assembly to the DbContext implementation.  These are referenced by the MVC project.</p>
  
  <p>I have the following in my Global.asax.cs:</p>
  
  <pre><code>protected void Application_Start()
  {
      var container = new Container();
  
      container.Register&lt;IContext, DbContext&gt;();
  
      container.RegisterMvcControllers(System.Reflection.Assembly.GetExecutingAssembly());
  
      container.RegisterMvcAttributeFilterProvider();
  
      container.Verify();
  
      DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
  
      // Regular MVC startup
      AreaRegistration.RegisterAllAreas();
  
      WebApiConfig.Register(GlobalConfiguration.Configuration);
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
      BundleConfig.RegisterBundles(BundleTable.Bundles);
  }
  </code></pre>
  
  <p>This is the stack trace:</p>
  
  <pre><code>[ActivationException: The constructor of the type HomeController contains the parameter of type IContext with name 'context' that is not registered. Please ensure IContext is registered in the container, or change the constructor of HomeController.]
  SimpleInjector.Advanced.DefaultConstructorInjectionBehavior.BuildParameterExpression(ParameterInfo parameter) +229
     SimpleInjector.Registration.BuildParameterExpressionFor(ParameterInfo parameter) +43
     SimpleInjector.Registration.BuildConstructorParameters(ConstructorInfo constructor) +170
     SimpleInjector.Registration.BuildNewExpression(Type serviceType, Type implementationType) +62
     SimpleInjector.Registration.BuildTransientExpression() +85
     SimpleInjector.Registration.BuildExpression(InstanceProducer producer) +62
     SimpleInjector.InstanceProducer.BuildExpressionInternal() +42
     System.Lazy`1.CreateValue() +14443208
     System.Lazy`1.LazyInitValue() +476
     SimpleInjector.InstanceProducer.BuildExpression() +159
  
   [ActivationException: The registered delegate for type HomeController threw an exception. The     constructor of the type HomeController contains the parameter of type IContext with name 'context' that is not registered. Please ensure IContext is registered in the container, or change the constructor of HomeController.]
     SimpleInjector.InstanceProducer.BuildExpression() +257
     SimpleInjector.InstanceProducer.VerifyExpressionBuilding() +53
  
  [InvalidOperationException: The configuration is invalid. Creating the instance for type HomeController failed. The registered delegate for type HomeController threw an exception. The constructor of the type HomeController contains the parameter of type IContext with name 'context' that is not registered. Please ensure IContext is registered in the container, or change the constructor of HomeController.]
     SimpleInjector.InstanceProducer.VerifyExpressionBuilding() +161
     SimpleInjector.Container.VerifyIfAllExpressionsCanBeBuilt(InstanceProducer[] producersToVerify) +45
     SimpleInjector.Container.VerifyIfAllExpressionsCanBeBuilt() +166
     SimpleInjector.Container.Verify() +39
     MyMvcApp.App_Start.SimpleInjectorInitializer.Initialize() +216
  
  [TargetInvocationException: Exception has been thrown by the target of an invocation.]
     System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
     System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +229
     System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +193
      System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35       
   WebActivator.BaseActivationMethodAttribute.InvokeMethod() +341
     WebActivator.ActivationManager.RunActivationMethods() +534
     WebActivator.ActivationManager.RunPostStartMethods() +38
     WebActivator.StartMethodCallingModule.Init(HttpApplication context) +159
     System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
     System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
     System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
     System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
  
  [HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12889028
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12730121
  </code></pre>
  
  <p>I have no idea why it isn't working as the code all is as per the Simple Injector quick start guide.</p>