我想知道当你有一个基本控制器时,如何使用 ninject 2.0 进行构造函数注入?
I have
private readonly IBaseService baseService;
public BaseController(IBaseService baseService)
{
this.baseService = baseService;
}
Bind<IBaseService>().To<BaseService>();
public class OtherController : BaseController
{
private readonly IOtherService otherService;
public OtherController(IOtherService otherService, IBaseService baseService)
{
this.otherService = otherService;
}
但我得到
“BaseController”不包含
带有 0 个参数的构造函数
您需要将这两个服务注入您的OtherController
并调用传递其所需服务的基本构造函数:
public OtherController(IOtherService otherService, IBaseService baseService)
: base(baseService) { this.otherService = otherService; }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)