我已经设置了我的项目Ninject IoC.
我的项目有常规Asp.Net MVC控制器和Web Api控制器.现在,Ninject使用Web Api但Ninject不适用于常规Asp.MVC控制器.
我的常规MVC控制器实现;
public class GalleryController : BaseController
{
public GalleryController(IUow uow)
{
Uow = uow;
}
........
}
Run Code Online (Sandbox Code Playgroud)
与常规控制器一起使用时出错
An error occurred when trying to create a controller of type 'Web.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
Run Code Online (Sandbox Code Playgroud)
但是,当我使用Web Api尝试相同的代码时,它可以工作
public class GalleryController : BaseApiController
{
public GalleryController(IUow uow)
{
Uow = …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc dependency-injection ninject repository-pattern