How to use Ninject bootstrapper in WebApi OwinHost Startup?

前端 未结 3 681
借酒劲吻你
借酒劲吻你 2021-02-01 20:52

I am migrating from IIS WebAPI to OwinHost. Utilizing the latest pre-release versions of nuget packages, I successfully used instructions here:

https://github.com/ninje

3条回答
  •  逝去的感伤
    2021-02-01 21:14

    Create the kernel manually and then make UseNinjectMiddleware use the same one instead of creating another.

    public void Configuration(IAppBuilder app)
    {
      var kernel = CreateKernel()
    
      var config = new HttpConfiguration();
      config.MapHttpAttributeRoutes();
    
      // USE kernel here
    
      app.UseNinjectMiddleware(() => kernel);
      app.UseNinjectWebApi(config);
    }
    

提交回复
热议问题