Skip to content

Commit

Permalink
Merge pull request #11106 from abpframework/liangshiwei/proxyService
Browse files Browse the repository at this point in the history
Add AreaAttribute to ClientProxy controller
  • Loading branch information
maliming authored Dec 29, 2021
2 parents 275fddb + 3822c3c commit 53058bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void AddApiDescriptionToModel(
var setting = FindSetting(controllerType);

var moduleModel = applicationModel.GetOrAddModule(
GetRootPath(controllerType, setting),
GetRootPath(controllerType, apiDescription.ActionDescriptor, setting),
GetRemoteServiceName(controllerType, setting)
);

Expand Down Expand Up @@ -327,15 +327,17 @@ public string GetMethodParamName(ParameterInfo parameterInfo)
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)
{
if (setting != null)
{
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)
{
return areaAttr.RouteValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,6 +51,15 @@ protected override void ApplyForControllers(ApplicationModel application)
{
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);
if (controllerApiDescription != null &&
!controllerApiDescription.ControllerGroupName.IsNullOrWhiteSpace())
Expand Down

0 comments on commit 53058bf

Please sign in to comment.