asp.net-mvc – 带基本控制器的Ninject?

我想知道如果你有一个基本控制器,你如何使用ninject 2.0进行构造函数注入?

我有

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’ does not contain a
constructor that takes 0 arguments

解决方法

您需要将两个服务注入到OtherController中并调用基础构造函数来传递它所需的服务:

public OtherController(IOtherService otherService,IBaseService baseService)
    : base(baseService) { this.otherService = otherService; }

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....