Search code examples
asp.net-coreaspnetboilerplate

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

  1. is it by default that the "service" word will also appear for task service like /taskservice in the route instead of just /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. Is there something similar in service level (which has module name as well)

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


Solution

  • By default, only the following postfixes are removed:

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

    You can do either of these:

    1. Name it TaskAppService.
    2. Configure ApplicationService.CommonPostfixes in your module's PreInitialize method.
    ApplicationService.CommonPostfixes = new string[] { "Service", "AppService", "ApplicationService" };
    

    References: