title: How to use Ninject bootstrapper in WebApi OwinHost Startup?
body: <p>I am migrating from IIS WebAPI to OwinHost.  Utilizing the latest pre-release versions of nuget packages, I successfully used instructions here:</p>
  
  <p><a href="https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application" rel="noreferrer">https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application</a></p>
  
  <p>Here is stub of my code:</p>
  
  <pre><code>    public void Configuration(IAppBuilder app)
      {
          var config = new HttpConfiguration();
          config.MapHttpAttributeRoutes();
  
          app.UseNinjectMiddleware(CreateKernel);
          app.UseNinjectWebApi(config);
      }
  
      private static StandardKernel CreateKernel()
      {
          var kernel = new StandardKernel();
          kernel.Load(Assembly.GetExecutingAssembly());
          RegisterServices(kernel);
          return kernel;
      }
  
      private static void RegisterServices(IKernel kernel)
      {
          ...
      }
  </code></pre>
  
  <p>But in my code and the documentation example, the Ninject kernel is not created until after Startup.  I need Ninject DI, however, in the Startup registration process for Cors and OAuth middleware registration.  Before migrating to OwinHost, I could do something like this:</p>
  
  <pre><code>public void Configuration(IAppBuilder app)
  {
    _bootstrapper = new Bootstrapper();
    _bootstrapper.Initialize(CreateKernel);           
  
    var config = new HttpConfiguration();
    config.MapHttpAttributeRoutes();
  
    // USE _boostrapper.Kernel here
  
    app.UseNinjectMiddleware(CreateKernel);
    app.UseNinjectWebApi(config);
  }
  </code></pre>
  
  <p>But internally, OwinBootstrapper.Execute will end up calling CreateKernel and bootstrapper.Initialize a second time, with bad consequences.   </p>
  
  <p>What is the right way to create and use the ninject kernel within Startup and still register the Ninject/WebAPI middleware?</p>