如何覆盖 AbpUserConfigurationController?

How to override the AbpUserConfigurationController?

不知道AbpUserConfigurationController的底层原理?它是如何注入到aspnet core DI容器中的?为什么在Swagger页面看不到呢?我正在使用 aspnetboilerplate 高级启动模板。

覆盖AbpUserConfigurationController

您可以使用aspnetboilerplate/#3296(comment)

中提到的方法

了解Abp如何将controller注入AspNetCore项目

@tseng解释,可以通过ApplicationPartManagerAddApplicationPart添加控制器。

Abp 在一些地方使用 ApplicationPartManager 来包含额外的控制器。

  1. Abp.AspNetCore中,正如@tseng所指出的,在AbpAspNetCoreModule#L47-78,这里的实现是包括在 Abp.AspNetCore 程序集中创建的控制器。

  2. 在下载的模板中,您可以在*.*.Web.Core项目下寻找*WebCoreModule.cs。下面的代码片段是Abp将MyProjectApplicationModule程序集中的所有应用服务转为controller的另一个地方

Configuration.Modules.AbpAspNetCore()
      .CreateControllersForAppServices(
          typeof(MyProjectApplicationModule).GetAssembly()
      );

您还可以查看 AbpAspNetCoreConfiguration.cs#L47-L55 正在更新 ControllerAssemblySettings 的位置。

请注意,CreateControllersForAppServicesAbpModulePreInitialize() 中调用,AddApplicationPartsAbpAspNetCoreModulePostInitialize() 中调用。

因此AbpAspNetCoreModule的方法AddApplicationParts中使用的ControllerAssemblySettings已经包含了所有要通过ApplicationPartManager

添加的控制器

理解为什么AbpUserConfigurationController没有大摇大摆地出现-ui

简而言之,常规路由不被Swagger支持,参见swashbuckle-apiexplorer-and-routing

TokenAuthController 出现在 swagger-ui 是因为它装饰有 [Route("api/[controller]/[action]")] (属性路由)