Browse Source

Resolved #3264: Allow a controller to set the remote service name to be used by clients

pull/3269/head
Halil İbrahim Kalkan 7 years ago
parent
commit
fe98008518
  1. 18
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  2. 11
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerOptions.cs
  3. 25
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs
  4. 7
      framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs
  5. 4
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApplicationApiDescriptionModel.cs
  6. 14
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs

18
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<RemoteServiceAttribute>().FirstOrDefault();
if (remoteServiceAttr?.Name != null)
{
return remoteServiceAttr.Name;
}
return ModuleApiDescriptionModel.DefaultRemoteServiceName;
}
[CanBeNull]
private ConventionalControllerSetting FindSetting(Type controllerType)
{

11
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<ConventionalControllerSetting> optionsAction = null)
public AbpConventionalControllerOptions Create(
Assembly assembly,
[CanBeNull] Action<ConventionalControllerSetting> 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);

25
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<Type, bool> TypePredicate { get; set; }
@ -46,15 +58,16 @@ namespace Volo.Abp.AspNetCore.Mvc.Conventions
public Action<ApiVersioningOptions> 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<Type>();
ApiVersions = new List<ApiVersion>();
}

7
framework/src/Volo.Abp.Core/Volo/Abp/RemoteServiceAttribute.cs

@ -17,6 +17,13 @@ namespace Volo.Abp
/// </summary>
public bool IsMetadataEnabled { get; set; }
/// <summary>
/// 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.
/// </summary>
public string Name { get; set; }
public RemoteServiceAttribute(bool isEnabled = true)
{
IsEnabled = isEnabled;

4
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)

14
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs

@ -11,10 +11,17 @@ namespace Volo.Abp.Http.Modeling
/// <summary>
/// "app".
/// </summary>
public const string DefaultRootPath = "app";
public const string DefaultRootPath = "app";
/// <summary>
/// "Default".
/// </summary>
public const string DefaultRemoteServiceName = "Default";
public string RootPath { get; set; }
public string RemoteServiceName { get; set; }
public IDictionary<string, ControllerApiDescriptionModel> 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<string, ControllerApiDescriptionModel>()
};
}
@ -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)
{

Loading…
Cancel
Save