Base solution for your next web application
Open Closed

AppService naming/routing question #12529


User avatar
0
pgummadapu created

Hello,

I have several modules in my app, one of the module names is Property Management.

I want to organize my appServices properly into each own modules. Is there a quick way of doing this without using Routes?

I was able to figure this out:

using [Route("api/services/app/PropertyManagement/Property/[action]")] on the top. Then I have to do:

[HttpPost] public async void GetTest()

Declare Http type in every method (something I do not do in any other service without the Route[]).

Is there a better way to create an AppService and make add "api/services/app/PropertyManagement/Property/[action]" path without using Routes?

Also, do I lose any of the functionality from the framework if I do Route and HttpPost/Get/etc ?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

6 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @pgummadapu

    Default Route Mechanism

    • In ASP.NET Boilerplate - Zero, every class that derives from ApplicationService is automatically exposed as a dynamic web API.
    • The default path format is

    /api/services/app/{AppServiceName}/{MethodName}

    • The {AppServiceName} is taken from the class name (PropertyAppService → Property).

    Adding a Module Prefix If you want your routes to look like

    /api/services/app/PropertyManagement/Property/GetTest
    

    you don’t need [Route]. Instead, use the RemoteService or DynamicApiController configuration.

    Example:

    [RemoteService(Name = "PropertyManagement")]
    public class PropertyAppService : ApplicationService, IPropertyAppService
    {
        public async Task<string> GetTestAsync()
        {
            return "Hello";
        }
    }
    

    This automatically adds "PropertyManagement" as the module name in the route.

    Do I Need [HttpPost] or [HttpGet]?

    • Normally, no.
    • The dynamic web API system decides whether to expose the method as GET or POST depending on the parameters.
    • You only need to explicitly add [HttpPost] or [HttpGet] if you want to override the default.

    Do I Lose Framework Features with [Route]? Yes, if you bypass the dynamic web API system with manual [Route].

    That’s why it’s recommended to stick with RemoteService/DynamicApiController instead of [Route].

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    pgummadapu created

    Hi, thank you for the answer, I am trying to use RemoteService but getting this issue with no suggestions on "using" top level statements

    Can you assist?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @pgummadapu

    I’m sorry, that was my fault. Change the prefix for the entire module

    If you want to put all services in the module under the same prefix, you can do

    public override void PreInitialize()
    {
        Configuration.Modules.AbpAspNetCore()
            .CreateControllersForAppServices(
                typeof(PropertyManagementApplicationModule).Assembly,
                moduleName: "app/PropertyManagement",
                useConventionalHttpVerbs: true
            );
    }
    

    With this configuration, all services in that module will be exposed as:

    /api/services/app/PropertyManagement/{ServiceName}/{MethodName}
    

    If you need any further information, please do not hesitate to contact us.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    pgummadapu created

    Thanks

    What if I want only certain AppService files to use this new PropertyManagement url addition, how would I do it?

    E.g. I have 5 AppService class files that I want to use /api/services/app/PropertyManagement/{ServiceName}/{MethodName} and several to use something else /api/services/app/SomethingElseGoesHere/{ServiceName}/{MethodName}

    I tried this and it doesn't work (to make this particular app service include PropertyManagement in the path),

      Configuration.Modules.AbpAspNetCore()
      .CreateControllersForAppServices(
      typeof(PropertyAppService).Assembly,
      moduleName: "app/PropertyManagement",
      useConventionalHttpVerbs: true
      );
      
    

    This is what I have, I need to leave certain app services as is and others need to append PropertyManagement in the path:

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    pgummadapu created

    Also, if I go back to using [Route], I know I will lose functionality of the framework identifying what is Get or Post etc based on my method name and I would have to identify [HttpGet] etc. What other functionality will I use?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @pgummadapu

    Sorry for the late reply. You’re right when you use [Route] attributes directly, you lose Zero’s conventional HTTP verb detection, so you’ll need to explicitly decorate each action with [HttpGet], [HttpPost], etc. You also lose some of the automatic proxy generation features that rely on the conventional route format.

    If you only want some AppServices to use /PropertyManagement/... while others stay under the default /app/..., you have two main options:

    1. Split by assembly

      • Move the PropertyManagement-related AppServices into their own assembly.
      • Then call CreateControllersForAppServices twice: once for the default ones, and once for the PropertyManagement ones with a different moduleName.
      Configuration.Modules.AbpAspNetCore()
          .CreateControllersForAppServices(
              typeof(DefaultAppService).Assembly,
              moduleName: "app",
              useConventionalHttpVerbs: true
          );
      
      Configuration.Modules.AbpAspNetCore()
          .CreateControllersForAppServices(
              typeof(PropertyAppService).Assembly,
              moduleName: "app/PropertyManagement",
              useConventionalHttpVerbs: true
          );
      

      This way, you don’t have to touch [Route] and you still keep Zero’s conventions.

    2. Stay in the same assembly but use attributes

      • If splitting assemblies isn’t an option, then yes, you’ll need to fall back to [Route] and [Http*] attributes on just those controllers.
      • This is more manual, and as you mentioned, you’ll lose the convention based features.
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)