title: Resolving dependencies in OWIN WEB API Startup.cs with ninject
body: <p>I have a Web Api 2 App, with two classes that both depend on another class, and i'm using ninject to resolve the dependancies.</p>
  
  <pre><code>public class AuthorizationServerProvider : OAuthAuthorizationServerProvider
  {
      private IUserService _userService;
  
  
      public AuthorizationServerProvider(IUserService userService)
      {
          _userService = userService;
      }
  
  }
  
  public class RefreshTokenProvider : IAuthenticationTokenProvider
  {
      private IUserService _userService;
  
      public RefreshTokenProvider(IUserService userService)
      {
          _userService = userService;
      }
  </code></pre>
  
  <p>In the startup.cs class i need to use the above two classes, but of course i cannot use constructor injection in the startup class, as that is initialised before Ninject is.</p>
  
  <p>What's a way around this so that the references to _tokenProvider and 
  _authServerProvider in the ConfigureAuth method?</p>
  
  <pre><code>public class Startup
  {
      private AuthorizationServerProvider _authServerProvider;        
      private RefreshTokenProvider _tokenProvider;
  
      public static OAuthBearerAuthenticationOptions OAuthBearerOptions { get; private set; }
      public void Configuration(IAppBuilder app)
      {
         var config = new HttpConfiguration();
  
          app.UseNinjectMiddleware(CreateKernel);
          app.UseNinjectWebApi(config);
  
          ConfigureOAuth(app);
  
          WebApiConfig.Register(config);
          app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
          app.UseWebApi(config);
  
      }
  
      public void ConfigureOAuth(IAppBuilder app)
      {
  
          var oAuthServerOptions = new OAuthAuthorizationServerOptions()
          {
              AllowInsecureHttp = true, //TODO: HTTPS
              TokenEndpointPath = new PathString("/token"),
              AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
              Provider = _authServerProvider, 
              RefreshTokenProvider = _tokenProvider
          };
  
  }
  </code></pre>
  
  <p>Here's the CreateKernel Method</p>
  
  <pre><code>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;();
  
  
              RegisterServices(kernel);
              return kernel;
          }
          catch
          {
              kernel.Dispose();
              throw;
          }
      }
  </code></pre>
  
  <p>And here's where I register my services</p>
  
  <pre><code>private static void RegisterServices(IKernel kernel)
      {
  
          kernel.Bind&lt;SimpleAuthorizationServerProvider&gt;().ToSelf();
          kernel.Bind&lt;SimpleRefreshTokenProvider&gt;().ToSelf();
  
  }
  </code></pre>
  
  <p>I've followed the advice in the ninject <a href="https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application" rel="noreferrer">docs</a>, but to no avail.</p>