Ninject error in WebAPI 2.1 - Make sure that the controller has a parameterless public constructor

后端 未结 10 2101
心在旅途
心在旅途 2020-12-31 00:39

I have the following packages and their dependencies installed in my WebAPI project:

Ninject.Web.WebApi Ninject.Web.WebApi.OwinHost

10条回答
  •  春和景丽
    2020-12-31 00:51

    I too was trying to make an 'only API' app, but faced similar issues. For me personally, in the end it came down the selecting the right starting template.

    Despite going for API-only, when in the 'Create a new ASP.NET Web Application" wizard, selecting the 'Empty' application-type and choosing MVC and Web API in the 'add folders & core references' section made Ninject work fine:

    As opposed to the 'Web API' application, which didn't play nice with Ninject:

    After that, it's simply to add the Ninject.Web.WebApi.WebHost package, which adds the NinjectWebCommon.cs class, and start adding dependencies.

提交回复
热议问题