diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs index 2077f275b4..31dc3b5cdb 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs @@ -25,24 +25,28 @@ namespace Volo.Abp.AspNetCore.Mvc } public void Apply(ApplicationModel application) + { + ApplyForControllers(application); + } + + protected virtual void ApplyForControllers(ApplicationModel application) { foreach (var controller in application.Controllers) { - var type = controller.ControllerType.AsType(); - var configuration = GetControllerSettingOrNull(type); + var controllerType = controller.ControllerType.AsType(); + var configuration = GetControllerSettingOrNull(controllerType); - if (typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(type)) + if (IsApplicationService(controllerType)) { controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes); configuration?.ControllerModelConfigurer(controller); - ConfigureArea(controller, configuration); ConfigureRemoteService(controller, configuration); } else { - var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault(type.GetTypeInfo()); - if (remoteServiceAtt != null && remoteServiceAtt.IsEnabledFor(type)) + var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOrDefault(controllerType.GetTypeInfo()); + if (remoteServiceAttr != null && remoteServiceAttr.IsEnabledFor(controllerType)) { ConfigureRemoteService(controller, configuration); } @@ -202,28 +206,32 @@ namespace Volo.Abp.AspNetCore.Mvc protected virtual void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) { - var verb = configuration?.UseConventionalHttpVerbs == true - ? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName) - : HttpVerbHelper.DefaultHttpVerb; + var httpMethod = SelectHttpMethod(action, configuration); var abpServiceSelectorModel = new SelectorModel { - AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, verb), - ActionConstraints = { new HttpMethodActionConstraint(new[] { verb }) } + AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, httpMethod), + ActionConstraints = { new HttpMethodActionConstraint(new[] { httpMethod }) } }; action.Selectors.Add(abpServiceSelectorModel); } + protected virtual string SelectHttpMethod(ActionModel action, AbpControllerAssemblySetting configuration) + { + return configuration?.UseConventionalHttpVerbs == true + ? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName) + : HttpVerbHelper.DefaultHttpVerb; + } + protected virtual void NormalizeSelectorRoutes(string moduleName, string controllerName, ActionModel action) { foreach (var selector in action.Selectors) { - //TODO: Revise this? - var method = selector.ActionConstraints.OfType().FirstOrDefault()?.HttpMethods?.FirstOrDefault(); + var httpMethod = selector.ActionConstraints.OfType().FirstOrDefault()?.HttpMethods?.FirstOrDefault(); if (selector.AttributeRouteModel == null) { - selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, method); + selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, httpMethod); } } } @@ -240,7 +248,7 @@ namespace Volo.Abp.AspNetCore.Mvc return _options.ControllerAssemblySettings.GetSettingOrNull(controllerType); } - protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string verb) + protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string httpMethod) { var url = $"api/services/{moduleName}/{controllerName}/{action.ActionName}"; return new AttributeRouteModel(new RouteAttribute(url)); @@ -258,5 +266,10 @@ namespace Volo.Abp.AspNetCore.Mvc { return selector.AttributeRouteModel == null && selector.ActionConstraints.IsNullOrEmpty(); } + + protected virtual bool IsApplicationService(Type controllerType) + { + return typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(controllerType); + } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs b/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs index c8a61c1f07..684d90b8af 100644 --- a/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs +++ b/src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs @@ -2,7 +2,7 @@ namespace Volo.Abp.Application.Services { public abstract class ApplicationService : AbpServiceBase, IApplicationService { - public static string[] CommonPostfixes = { "AppService", "ApplicationService", "Service" }; + public static string[] CommonPostfixes { get; set; } = { "AppService", "ApplicationService", "Service" }; /* Will be added when implemented - AbpSession