Ninject有基本控制器? [英] Ninject with a base controller?
本文介绍了Ninject有基本控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道你是怎么做到的构造与ninject 2.0注入,当你有一个基本的控制器?
我
私人只读IBaseService baseService; 公共BaseController(IBaseService baseService)
{
this.baseService = baseService; }
绑定&所述; IBaseService方式>()到< BaseService>();
公共类OtherController:BaseController
{
私人只读IOtherService otherService; 公共OtherController(IOtherService otherService,IBaseService baseService)
{
this.otherService = otherService;
}
不过,我得到
BaseController'不包含一
构造函数的参数0
块引用>解决方案您需要这两种服务注入到你的
OtherController
和调用基构造函数传递所需的服务:公共OtherController(IOtherService otherService,IBaseService baseService)
:基地(baseService){this.otherService = otherService; }I am wondering how do you do constructor inject with ninject 2.0 when you have a base controller?
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; }
Yet I get
'BaseController' does not contain a constructor that takes 0 arguments
解决方案You need to inject both services into your
OtherController
and call the base constructor passing the service it requires:public OtherController(IOtherService otherService, IBaseService baseService) : base(baseService) { this.otherService = otherService; }
这篇关于Ninject有基本控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文