Browse Source

Merge pull request #11106 from abpframework/liangshiwei/proxyService

Add AreaAttribute to ClientProxy controller
pull/11110/head
maliming 4 years ago
committed by GitHub
parent
commit
53058bfdb5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  2. 10
      framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs

8
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -80,7 +80,7 @@ namespace Volo.Abp.AspNetCore.Mvc
var setting = FindSetting(controllerType); var setting = FindSetting(controllerType);
var moduleModel = applicationModel.GetOrAddModule( var moduleModel = applicationModel.GetOrAddModule(
GetRootPath(controllerType, setting), GetRootPath(controllerType, apiDescription.ActionDescriptor, setting),
GetRemoteServiceName(controllerType, setting) GetRemoteServiceName(controllerType, setting)
); );
@ -327,7 +327,9 @@ namespace Volo.Abp.AspNetCore.Mvc
return modelNameProvider.Name ?? parameterInfo.Name; return modelNameProvider.Name ?? parameterInfo.Name;
} }
private static string GetRootPath([NotNull] Type controllerType, private static string GetRootPath(
[NotNull] Type controllerType,
[NotNull] ActionDescriptor actionDescriptor,
[CanBeNull] ConventionalControllerSetting setting) [CanBeNull] ConventionalControllerSetting setting)
{ {
if (setting != null) if (setting != null)
@ -335,7 +337,7 @@ namespace Volo.Abp.AspNetCore.Mvc
return setting.RootPath; return setting.RootPath;
} }
var areaAttr = controllerType.GetCustomAttributes().OfType<AreaAttribute>().FirstOrDefault(); var areaAttr = controllerType.GetCustomAttributes().OfType<AreaAttribute>().FirstOrDefault() ?? actionDescriptor.EndpointMetadata.OfType<AreaAttribute>().FirstOrDefault();
if (areaAttr != null) if (areaAttr != null)
{ {
return areaAttr.RouteValue; return areaAttr.RouteValue;

10
framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -50,6 +51,15 @@ namespace Volo.Abp.Http.Client.Web.Conventions
{ {
controller.ControllerName = controller.ControllerName.RemovePostFix("ClientProxy"); controller.ControllerName = controller.ControllerName.RemovePostFix("ClientProxy");
var moduleApiDescription = FindModuleApiDescriptionModel(controller);
if (moduleApiDescription != null && !moduleApiDescription.RootPath.IsNullOrWhiteSpace())
{
var selector = controller.Selectors.FirstOrDefault();
selector?.EndpointMetadata.Add(new AreaAttribute(moduleApiDescription.RootPath));
controller.RouteValues.Add(new KeyValuePair<string, string>("area", moduleApiDescription.RootPath));
}
var controllerApiDescription = FindControllerApiDescriptionModel(controller); var controllerApiDescription = FindControllerApiDescriptionModel(controller);
if (controllerApiDescription != null && if (controllerApiDescription != null &&
!controllerApiDescription.ControllerGroupName.IsNullOrWhiteSpace()) !controllerApiDescription.ControllerGroupName.IsNullOrWhiteSpace())

Loading…
Cancel
Save