Browse Source

feat(settings): merge settings api to cancel aggregation at the gateway layer.

pull/898/head
colin 2 years ago
parent
commit
3077d5c82c
  1. 36
      aspnet-core/framework/settings/LINGYUN.Abp.SettingManagement.Application.Contracts/LINGYUN/Abp/SettingManagement/AbpSettingManagementApplicationContractsModule.cs
  2. 13
      aspnet-core/framework/settings/LINGYUN.Abp.SettingManagement.Application.Contracts/LINGYUN/Abp/SettingManagement/SettingManagementMergeOptions.cs
  3. 70
      aspnet-core/services/LY.MicroService.Applications.Single/Controllers/SettingMergeController.cs
  4. 45
      aspnet-core/services/LY.MicroService.Applications.Single/Controllers/UserSettingMergeController.cs
  5. 74
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Controllers/SettingMergeController.cs
  6. 49
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Controllers/UserSettingMergeController.cs

36
aspnet-core/framework/settings/LINGYUN.Abp.SettingManagement.Application.Contracts/LINGYUN/Abp/SettingManagement/AbpSettingManagementApplicationContractsModule.cs

@ -1,4 +1,7 @@
using Volo.Abp.Application; using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using Volo.Abp.Application;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.SettingManagement; using Volo.Abp.SettingManagement;
@ -11,6 +14,11 @@ namespace LINGYUN.Abp.SettingManagement
[DependsOn(typeof(AbpSettingManagementDomainSharedModule))] [DependsOn(typeof(AbpSettingManagementDomainSharedModule))]
public class AbpSettingManagementApplicationContractsModule : AbpModule public class AbpSettingManagementApplicationContractsModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context)
{
AutoAddSettingProviders(context.Services);
}
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
@ -25,5 +33,31 @@ namespace LINGYUN.Abp.SettingManagement
.AddVirtualJson("/LINGYUN/Abp/SettingManagement/Localization/ApplicationContracts"); .AddVirtualJson("/LINGYUN/Abp/SettingManagement/Localization/ApplicationContracts");
}); });
} }
private static void AutoAddSettingProviders(IServiceCollection services)
{
var userSettingProviders = new List<Type>();
var globalSettingProviders = new List<Type>();
services.OnRegistered(context =>
{
if (typeof(IUserSettingAppService).IsAssignableFrom(context.ImplementationType) &&
context.ImplementationType.Name.EndsWith("AppService"))
{
userSettingProviders.Add(context.ImplementationType);
}
if (typeof(IReadonlySettingAppService).IsAssignableFrom(context.ImplementationType) &&
context.ImplementationType.Name.EndsWith("AppService"))
{
globalSettingProviders.Add(context.ImplementationType);
}
});
services.Configure<SettingManagementMergeOptions>(options =>
{
options.UserSettingProviders.AddIfNotContains(userSettingProviders);
options.GlobalSettingProviders.AddIfNotContains(globalSettingProviders);
});
}
} }
} }

13
aspnet-core/framework/settings/LINGYUN.Abp.SettingManagement.Application.Contracts/LINGYUN/Abp/SettingManagement/SettingManagementMergeOptions.cs

@ -0,0 +1,13 @@
using Volo.Abp.Collections;
namespace LINGYUN.Abp.SettingManagement;
public class SettingManagementMergeOptions
{
public ITypeList<IUserSettingAppService> UserSettingProviders { get; }
public ITypeList<IReadonlySettingAppService> GlobalSettingProviders { get; }
public SettingManagementMergeOptions()
{
UserSettingProviders = new TypeList<IUserSettingAppService>();
GlobalSettingProviders = new TypeList<IReadonlySettingAppService>();
}
}

70
aspnet-core/services/LY.MicroService.Applications.Single/Controllers/SettingMergeController.cs

@ -0,0 +1,70 @@
using LINGYUN.Abp.SettingManagement;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace LY.MicroService.Applications.Single.Controllers;
[ExposeServices(
typeof(SettingController),
typeof(SettingMergeController))]
public class SettingMergeController : SettingController
{
private readonly SettingManagementMergeOptions _mergeOptions;
public SettingMergeController(
ISettingAppService settingAppService,
ISettingTestAppService settingTestAppService,
IOptions<SettingManagementMergeOptions> mergeOptions)
: base(settingAppService, settingTestAppService)
{
_mergeOptions = mergeOptions.Value;
}
[HttpGet]
[Route("by-current-tenant")]
public async override Task<SettingGroupResult> GetAllForCurrentTenantAsync()
{
var result = new SettingGroupResult();
var markTypeMap = new List<Type>
{
typeof(SettingMergeController),
};
foreach (var serviceType in _mergeOptions.GlobalSettingProviders
.Where(type => !markTypeMap.Any(markType => type.IsAssignableFrom(markType))))
{
var settingService = LazyServiceProvider.LazyGetRequiredService(serviceType).As<IReadonlySettingAppService>();
var currentResult = await settingService.GetAllForCurrentTenantAsync();
foreach (var group in currentResult.Items)
{
result.AddGroup(group);
}
markTypeMap.Add(serviceType);
}
return result;
}
[HttpGet]
[Route("by-global")]
public async override Task<SettingGroupResult> GetAllForGlobalAsync()
{
var result = new SettingGroupResult();
var markTypeMap = new List<Type>
{
typeof(SettingMergeController),
};
foreach (var serviceType in _mergeOptions.GlobalSettingProviders
.Where(type => !markTypeMap.Any(markType => type.IsAssignableFrom(markType))))
{
var settingService = LazyServiceProvider.LazyGetRequiredService(serviceType).As<IReadonlySettingAppService>();
var currentResult = await settingService.GetAllForGlobalAsync();
foreach (var group in currentResult.Items)
{
result.AddGroup(group);
}
markTypeMap.Add(serviceType);
}
return result;
}
}

45
aspnet-core/services/LY.MicroService.Applications.Single/Controllers/UserSettingMergeController.cs

@ -0,0 +1,45 @@
using LINGYUN.Abp.SettingManagement;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace LY.MicroService.Applications.Single.Controllers;
[ExposeServices(
typeof(UserSettingController),
typeof(UserSettingMergeController))]
public class UserSettingMergeController : UserSettingController
{
private readonly SettingManagementMergeOptions _mergeOptions;
public UserSettingMergeController(
IUserSettingAppService service,
IOptions<SettingManagementMergeOptions> mergeOptions)
: base(service)
{
_mergeOptions = mergeOptions.Value;
}
[HttpGet]
[Route("by-current-user")]
public async override Task<SettingGroupResult> GetAllForCurrentUserAsync()
{
var result = new SettingGroupResult();
var markTypeMap = new List<Type>
{
typeof(UserSettingMergeController),
};
foreach (var serviceType in _mergeOptions.UserSettingProviders
.Where(type => !markTypeMap.Any(markType => type.IsAssignableFrom(markType))))
{
var settingService = LazyServiceProvider.LazyGetRequiredService(serviceType).As<IUserSettingAppService>();
var currentResult = await settingService.GetAllForCurrentUserAsync();
foreach (var group in currentResult.Items)
{
result.AddGroup(group);
}
markTypeMap.Add(serviceType);
}
return result;
}
}

74
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Controllers/SettingMergeController.cs

@ -0,0 +1,74 @@
using LINGYUN.Abp.SettingManagement;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace LY.MicroService.BackendAdmin.Controllers;
[ExposeServices(
typeof(SettingController),
typeof(SettingMergeController))]
public class SettingMergeController : SettingController
{
private readonly SettingManagementMergeOptions _mergeOptions;
public SettingMergeController(
ISettingAppService settingAppService,
ISettingTestAppService settingTestAppService,
IOptions<SettingManagementMergeOptions> mergeOptions)
: base(settingAppService, settingTestAppService)
{
_mergeOptions = mergeOptions.Value;
}
[HttpGet]
[Route("by-current-tenant")]
public async override Task<SettingGroupResult> GetAllForCurrentTenantAsync()
{
var result = new SettingGroupResult();
var markTypeMap = new List<Type>
{
typeof(SettingMergeController),
};
foreach (var serviceType in _mergeOptions.GlobalSettingProviders
.Where(type => !markTypeMap.Any(markType => type.IsAssignableFrom(markType))))
{
var settingService = LazyServiceProvider.LazyGetRequiredService(serviceType).As<IReadonlySettingAppService>();
var currentResult = await settingService.GetAllForCurrentTenantAsync();
foreach (var group in currentResult.Items)
{
result.AddGroup(group);
}
markTypeMap.Add(serviceType);
}
return result;
}
[HttpGet]
[Route("by-global")]
public async override Task<SettingGroupResult> GetAllForGlobalAsync()
{
var result = new SettingGroupResult();
var markTypeMap = new List<Type>
{
typeof(SettingMergeController),
};
foreach (var serviceType in _mergeOptions.GlobalSettingProviders
.Where(type => !markTypeMap.Any(markType => type.IsAssignableFrom(markType))))
{
var settingService = LazyServiceProvider.LazyGetRequiredService(serviceType).As<IReadonlySettingAppService>();
var currentResult = await settingService.GetAllForGlobalAsync();
foreach (var group in currentResult.Items)
{
result.AddGroup(group);
}
markTypeMap.Add(serviceType);
}
return result;
}
}

49
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Controllers/UserSettingMergeController.cs

@ -0,0 +1,49 @@
using LINGYUN.Abp.SettingManagement;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace LY.MicroService.BackendAdmin.Controllers;
[ExposeServices(
typeof(UserSettingController),
typeof(UserSettingMergeController))]
public class UserSettingMergeController : UserSettingController
{
private readonly SettingManagementMergeOptions _mergeOptions;
public UserSettingMergeController(
IUserSettingAppService service,
IOptions<SettingManagementMergeOptions> mergeOptions)
: base(service)
{
_mergeOptions = mergeOptions.Value;
}
[HttpGet]
[Route("by-current-user")]
public async override Task<SettingGroupResult> GetAllForCurrentUserAsync()
{
var result = new SettingGroupResult();
var markTypeMap = new List<Type>
{
typeof(UserSettingMergeController),
};
foreach (var serviceType in _mergeOptions.UserSettingProviders
.Where(type => !markTypeMap.Any(markType => type.IsAssignableFrom(markType))))
{
var settingService = LazyServiceProvider.LazyGetRequiredService(serviceType).As<IUserSettingAppService>();
var currentResult = await settingService.GetAllForCurrentUserAsync();
foreach (var group in currentResult.Items)
{
result.AddGroup(group);
}
markTypeMap.Add(serviceType);
}
return result;
}
}
Loading…
Cancel
Save