title: Using ninject with Ninject.Web.Api for Web Api 2 is not working in ASP.NET MVC 5
body: <p>I am developing an Asp.NET MVC project. My project has web api as well. I am using ASP.NET MVC5 and Web Api 2 with Visual Studio 3. I am doing dependency injection using ninject. I know ninject for web is not working for Web Api 2. So I tried to use Ninject for Web Api.</p>
  
  <p>I installed ninject for web api 2 package using nuget package manager</p>
  
  <p><a href="https://i.stack.imgur.com/ffoV8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ffoV8.png" alt="enter image description here"></a></p>
  
  <p>Then I installed Ninject.Web using nuget package manager</p>
  
  <p><a href="https://i.stack.imgur.com/bbWIa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bbWIa.png" alt="enter image description here"></a></p>
  
  <p>Then in NinjectWebCommon, I added this line in RegisterServices</p>
  
  <pre><code>private static void RegisterServices(IKernel kernel)
          {
              System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new Ninject.WebApi.DependencyResolver.NinjectDependencyResolver(kernel);
              kernel.Bind&lt;ICategoryRepo&gt;().To&lt;CategoryRepo&gt;();
          }    
  </code></pre>
  
  <p>This is my full NinjectWebCommon class registering one dependency</p>
  
  <pre><code>[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(PatheinFashionStore.Web.App_Start.NinjectWebCommon), "Start")]
  [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(PatheinFashionStore.Web.App_Start.NinjectWebCommon), "Stop")]
  
  namespace PatheinFashionStore.Web.App_Start
  {
      using System;
      using System.Web;
  
      using Microsoft.Web.Infrastructure.DynamicModuleHelper;
  
      using Ninject;
      using Ninject.Web.Common;
      using PatheinFashionStore.Domain.Abstract;
      using PatheinFashionStore.Domain.Concrete;
  
      public static class NinjectWebCommon 
      {
          private static readonly Bootstrapper bootstrapper = new Bootstrapper();
  
          /// &lt;summary&gt;
          /// Starts the application
          /// &lt;/summary&gt;
          public static void Start() 
          {
              DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
              DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
              bootstrapper.Initialize(CreateKernel);
          }
  
          /// &lt;summary&gt;
          /// Stops the application.
          /// &lt;/summary&gt;
          public static void Stop()
          {
              bootstrapper.ShutDown();
          }
  
          /// &lt;summary&gt;
          /// Creates the kernel that will manage your application.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;The created kernel.&lt;/returns&gt;
          private static IKernel CreateKernel()
          {
              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;();
                  System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new Ninject.WebApi.DependencyResolver.NinjectDependencyResolver(kernel);
                  RegisterServices(kernel);
                  return kernel;
              }
              catch
              {
                  kernel.Dispose();
                  throw;
              }
          }
  
          /// &lt;summary&gt;
          /// Load your modules or register your services here!
          /// &lt;/summary&gt;
          /// &lt;param name="kernel"&gt;The kernel.&lt;/param&gt;
          private static void RegisterServices(IKernel kernel)
          {
  
              kernel.Bind&lt;ICategoryRepo&gt;().To&lt;CategoryRepo&gt;();
          }        
      }
  }
  </code></pre>
  
  <p>This is my Controller</p>
  
  <pre><code> public class HomeController : Controller
      {
          private ICategoryRepo categoryRepo;
  
          public HomeController(ICategoryRepo categoryRepoParam)
          {
              this.categoryRepo = categoryRepoParam;
          }
  
          public ActionResult Index()
          {
              return View();
          }
  }
  </code></pre>
  
  <p>Then when I run my code, it is giving me this error</p>
  
  <p><a href="https://i.stack.imgur.com/hp01G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hp01G.png" alt="enter image description here"></a></p>
  
  <h2>Update</h2>
  
  <p>But when I access apiController, it is working. </p>
  
  <p>Here is my web api controller</p>
  
  <pre><code> public class TestController : ApiController
      {
          private ICategoryRepo categoryRepo;
  
          public TestController(ICategoryRepo categoryRepoParam)
          {
              this.categoryRepo = categoryRepoParam;
          }
  
          public string Get()
          {
              this.categoryRepo.Create();
              return "OK";
          }
      }
  </code></pre>
  
  <p>So what I found out is it is working for web api, but not working for web project. I am using both in the same project.</p>