简体   繁体   English

ABP 将 Controller 中的 API 路由重命名为服务

[英]ABP Rename API Route in Controller as a Service

Using ABP service as controller, a default route as such will be generated for a TaskService get method: /api/services/app/taskservice/gettask使用 ABP 服务作为 controller,将为 TaskService 获取方法生成默认路由:/api/services/app/taskservice/gettask

  1. is it by default that the "service" word will also appear for task service like /taskservice in the route instead of just /task?默认情况下,“服务”一词是否也会出现在路由中的 /taskservice 之类的任务服务中,而不仅仅是 /task? If it's not, what could be wrong in my setup?如果不是,我的设置可能有什么问题?

  2. If it is, how can I remove it?如果是,我该如何删除它? Like in controller level, I can have api route as such /api/v1/task/gettask by having data annotation below.就像在 controller 级别中一样,我可以通过下面的数据注释来拥有 api 路由这样的 /api/v1/task/gettask 。 Is there something similar in service level (which has module name as well)服务级别是否有类似的东西(也有模块名称)

    [Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]

The service have to named as "AppService" as the postfix instead of just "Service"该服务必须命名为“AppService”作为后缀,而不仅仅是“服务”

By default, only the following postfixes are removed:默认情况下,仅删除以下后缀:

public static string[] CommonPostfixes = { "AppService", "ApplicationService" };

You can do either of these:您可以执行以下任一操作:

  1. Name it TaskAppService .将其命名为TaskAppService
  2. Configure ApplicationService.CommonPostfixes in your module's PreInitialize method.在模块的PreInitialize方法中配置ApplicationService.CommonPostfixes
ApplicationService.CommonPostfixes = new string[] { "Service", "AppService", "ApplicationService" };

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM