.Net Core Api 控制器继承

Duk*_*lus 5 .net-core asp.net-core-webapi

我正在尝试创建一个可以在多个 API 项目中使用的 API 模块。我希望模块有一个控制器,其动作可以根据实现的 API 要求进行覆盖。

我有以下项目结构:

Module
    -Controllers
        -ModuleController.cs
    -Interfaces
        -IModel.cs
    -Models
        -Model.cs

API
    -Controllers
        -DerivedModuleController.cs
Run Code Online (Sandbox Code Playgroud)

IModel.cs

public interface IModel
    {
        int Id { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

模型.cs

public class Model : IModel
    {
        public int Id { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

模块控制器.cs

[Route("api/module/[action]")]
    public class ModuleController : Controller
    {
        [ActionName("GetModel")]
        [HttpGet("{id}")]
        public virtual Model GetModel(int id)
        {
            return new Model() { Id = id };
        }
    }
Run Code Online (Sandbox Code Playgroud)

派生模块控制器.cs

public class DerivedModuleController : ModuleController
    {
        public override Model GetModel(int id)
        {
            return base.GetModel(id);
        }
    }
Run Code Online (Sandbox Code Playgroud)

API 项目引用了模块。如果我删除 DerivedModuleController 一切正常。我可以提出请求/api/module/GetModel/1并获得有效结果。但是,当我添加 DerivedModuleController 时,它失败并出现以下错误:

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

Api.Controllers.DerivedModuleController.GetModel (Api)
Module.ModuleController.GetModel (Module)
Run Code Online (Sandbox Code Playgroud)

最终,我希望能够获得从DerivedModel延伸的ModelDerivedModuleController但我无法克服此错误。

有没有办法使用基本路由 ( /api/module/GetModel/1) 访问 DerivedModuleController 并忽略 ModuleController?