Skip to content

Commit

Permalink
Add AreaAttribute to ClientProxy controller
Browse files Browse the repository at this point in the history
  • Loading branch information
realLiangshiwei committed Dec 29, 2021
1 parent 275fddb commit de6dfb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 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,7 +327,9 @@ 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)
Expand All @@ -341,6 +343,12 @@ private static string GetRootPath([NotNull] Type controllerType,
return areaAttr.RouteValue;
}

areaAttr = actionDescriptor.EndpointMetadata.OfType<AreaAttribute>().FirstOrDefault();
if (areaAttr != null)
{
return areaAttr.RouteValue;
}

return ModuleApiDescriptionModel.DefaultRootPath;
}

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 de6dfb3

Please sign in to comment.