title: Ninject can't resolve a dependency for a controller, but have no problems with services
body: <p>1) I'm creating an ASP.NET MVC app and want to make use of <code>DbContext</code> right in the app itself, along with some simple services that are slightly resembling a layered architecture.</p>
  
  <p>So, I'm registering the dependency in the standard <code>NinjectWebCommon</code> bootstrapper:</p>
  
  <pre><code>kernel
      .Bind&lt;IDbContextFactory&lt;WebDbContext&gt;&gt;()
      .To&lt;WebDbContextFactory&gt;()
      .InRequestScope()
      .WithPropertyValue(nameof(WebDbContextFactory.ConnectionString), ConfigurationManager.ConnectionStrings["WebDb"].ConnectionString);
  </code></pre>
  
  <p>It works as expected, if it initializes some <code>MyService</code> class with the <code>IDbContextFactory&lt;WebDbContext&gt;</code> dependency in its constructor. In debug I see an initialized instance.</p>
  
  <p>However, if <code>MyController</code> has a constructor with the same dependency, Ninject throws an exception that the dependency is not registered.</p>
  
  <p>Hm, why?</p>
  
  <p>2) And the Kernel initialization is following:</p>
  
  <pre><code>var kernel = new StandardKernel();
      try
      {
          kernel.Bind&lt;Func&lt;IKernel&gt;&gt;().ToMethod(ctx =&gt; () =&gt; new Bootstrapper().Kernel);
          kernel.Bind&lt;IHttpModule&gt;().To&lt;HttpApplicationInitializationHttpModule&gt;();
  
          RegisterServices(kernel);
  
          ControllerBuilder.Current.SetControllerFactory(new ControllerFactory(kernel));
          DependencyResolver.SetResolver(new AppDependencyResolver(kernel));
  
          return kernel;
      }
  ...
  </code></pre>
  
  <p><code>RegisterServices()</code> method contains that dependency registration, so I assume the kernel already has it when passed to the controller factory, for example.</p>
  
  <p>3) And one more thing. The DB context factory isn't the only dependency that <code>MyController</code> is pulling when initializing. There are a couple like:</p>
  
  <pre><code>kernel.Bind&lt;MyService&gt;().ToSelf().InRequestScope();
  </code></pre>
  
  <p>So if I workaround the <code>IDbContextFactory</code> dependency in <code>MyController</code>, it has no problems with the other dependencies.</p>
  
  <p>4) And another thing. The possible workaround is to change the DB context factory registration to this:</p>
  
  <pre><code>kernel
      .Bind&lt;IDbContextFactory&lt;WebDbContext&gt;, WebDbContextFactory&gt;()
      .To&lt;WebDbContextFactory&gt;()
      .InRequestScope()
      .WithPropertyValue(nameof(WebDbContextFactory.ConnectionString), ConfigurationManager.ConnectionStrings["WebDb"].ConnectionString);
  </code></pre>
  
  <p>Notice the second type in <code>Bind()</code> method. With corresponding changes in the <code>MyController</code> constructor, of course. But <code>WebDbContextFactory</code> is in fact <code>WebDbContextFactory : IDbContextFactory&lt;WebDbContext&gt;</code>. The only way it's different is, I think, that it is in my local assembly (another referenced project, though) and <code>IDbContextFactory&lt;&gt;</code> is an external one. Huh?</p>