diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index aefad0f02e..f957fd894f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -73,7 +73,7 @@ namespace Volo.Abp.AspNetCore.Mvc var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(); var setting = FindSetting(controllerType); - var moduleModel = applicationModel.GetOrAddModule(GetRootPath(controllerType, setting)); + var moduleModel = applicationModel.GetOrAddModule(GetRootPath(controllerType, setting), GetRemoteServiceName(controllerType, setting)); var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces); @@ -289,6 +289,22 @@ namespace Volo.Abp.AspNetCore.Mvc return ModuleApiDescriptionModel.DefaultRootPath; } + private string GetRemoteServiceName(Type controllerType, [CanBeNull] ConventionalControllerSetting setting) + { + if (setting != null) + { + return setting.RemoteServiceName; + } + + var remoteServiceAttr = controllerType.GetCustomAttributes().OfType().FirstOrDefault(); + if (remoteServiceAttr?.Name != null) + { + return remoteServiceAttr.Name; + } + + return ModuleApiDescriptionModel.DefaultRemoteServiceName; + } + [CanBeNull] private ConventionalControllerSetting FindSetting(Type controllerType) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerOptions.cs index e28ff37717..e21e6ee939 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerOptions.cs @@ -23,9 +23,16 @@ namespace Volo.Abp.AspNetCore.Mvc.Conventions }; } - public AbpConventionalControllerOptions Create(Assembly assembly, [CanBeNull] Action optionsAction = null) + public AbpConventionalControllerOptions Create( + Assembly assembly, + [CanBeNull] Action optionsAction = null) { - var setting = new ConventionalControllerSetting(assembly, ModuleApiDescriptionModel.DefaultRootPath); + var setting = new ConventionalControllerSetting( + assembly, + ModuleApiDescriptionModel.DefaultRootPath, + ModuleApiDescriptionModel.DefaultRemoteServiceName + ); + optionsAction?.Invoke(setting); setting.Initialize(); ConventionalControllerSettings.Add(setting); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs index fac627d182..bae2522d20 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs @@ -30,6 +30,18 @@ namespace Volo.Abp.AspNetCore.Mvc.Conventions } private string _rootPath; + [NotNull] + public string RemoteServiceName + { + get => _remoteServiceName; + set + { + Check.NotNull(value, nameof(value)); + _remoteServiceName = value; + } + } + private string _remoteServiceName; + [CanBeNull] public Func TypePredicate { get; set; } @@ -46,15 +58,16 @@ namespace Volo.Abp.AspNetCore.Mvc.Conventions public Action ApiVersionConfigurer { get; set; } - public ConventionalControllerSetting([NotNull] Assembly assembly, [NotNull] string rootPath) + public ConventionalControllerSetting( + [NotNull] Assembly assembly, + [NotNull] string rootPath, + [NotNull] string remoteServiceName) { - Check.NotNull(assembly, rootPath); - - Assembly = assembly; - RootPath = rootPath; + Assembly = Check.NotNull(assembly, nameof(assembly)); + RootPath = Check.NotNull(rootPath, nameof(rootPath)); + RemoteServiceName = Check.NotNull(remoteServiceName, nameof(remoteServiceName)); ControllerTypes = new HashSet(); - ApiVersions = new List(); } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs b/framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs index e866022437..84e46e2709 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs @@ -17,6 +17,13 @@ namespace Volo.Abp /// public bool IsMetadataEnabled { get; set; } + /// + /// Group name of the remote service. + /// Group names of all services of a module expected to be the same. + /// This name is also used to distinguish the service endpoint of this group. + /// + public string Name { get; set; } + public RemoteServiceAttribute(bool isEnabled = true) { IsEnabled = isEnabled; diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs index fad94b3745..cc09b7a153 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs @@ -36,9 +36,9 @@ namespace Volo.Abp.Http.Modeling return Modules[module.RootPath] = module; } - public ModuleApiDescriptionModel GetOrAddModule(string rootPath) + public ModuleApiDescriptionModel GetOrAddModule(string rootPath, string remoteServiceName) { - return Modules.GetOrAdd(rootPath, () => ModuleApiDescriptionModel.Create(rootPath)); + return Modules.GetOrAdd(rootPath, () => ModuleApiDescriptionModel.Create(rootPath, remoteServiceName)); } public ApplicationApiDescriptionModel CreateSubModel(string[] modules = null, string[] controllers = null, string[] actions = null) diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs index 44967fa50c..b879b90135 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs @@ -11,10 +11,17 @@ namespace Volo.Abp.Http.Modeling /// /// "app". /// - public const string DefaultRootPath = "app"; + public const string DefaultRootPath = "app"; + /// + /// "Default". + /// + public const string DefaultRemoteServiceName = "Default"; + public string RootPath { get; set; } + public string RemoteServiceName { get; set; } + public IDictionary Controllers { get; set; } private ModuleApiDescriptionModel() @@ -22,11 +29,12 @@ namespace Volo.Abp.Http.Modeling } - public static ModuleApiDescriptionModel Create(string rootPath) + public static ModuleApiDescriptionModel Create(string rootPath, string remoteServiceName) { return new ModuleApiDescriptionModel { RootPath = rootPath, + RemoteServiceName = remoteServiceName, Controllers = new Dictionary() }; } @@ -48,7 +56,7 @@ namespace Volo.Abp.Http.Modeling public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions) { - var subModel = Create(RootPath); + var subModel = Create(RootPath, RemoteServiceName); foreach (var controller in Controllers.Values) {