How to use Ninject with ASP.NET Web API?

前端 未结 4 1301
悲哀的现实
悲哀的现实 2020-12-05 18:36

In MVC I simply make the class NinjectControllerFactory that implements DefaultControllerFactory interface then do some bindings in it. at last in

4条回答
  •  借酒劲吻你
    2020-12-05 19:26

    The following steps work like a sharm to get Ninject working on an WebAPI project:

    1. Install the Ninject.Web.WebApi NuGet package.
    2. Install the Ninject.Web.WebApi.WebHost NuGet package.
    3. Register your dependencies in the method "RegisterServices" in the file NinjectWebCommon added to the App_Start folder. Like this:

    Private static void RegisterServices(IKernel kernel)
    {

      kernel.Bind ().To ();
    
    } 
    

提交回复
热议问题