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 ?
6 Answer(s)
-
0
Hi @pgummadapu
Default Route Mechanism
- In ASP.NET Boilerplate - Zero, every class that derives from
ApplicationServiceis 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/GetTestyou don’t need
[Route]. Instead, use theRemoteServiceorDynamicApiControllerconfiguration.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/DynamicApiControllerinstead of[Route].Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) - In ASP.NET Boilerplate - Zero, every class that derives from
-
0
-
0
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 supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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 supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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 supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
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:Split by assembly
- Move the PropertyManagement-related AppServices into their own assembly.
- Then call
CreateControllersForAppServicestwice: once for the default ones, and once for the PropertyManagement ones with a differentmoduleName.
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.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.
- If splitting assemblies isn’t an option, then yes, you’ll need to fall back to
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)

