Merge pull request #3183 from abpframework/Cotur-Virtualization-SettingManagement

Make Setting Management module services easily overridable by inheritance
pull/3205/head
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit df80a63bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,17 +16,17 @@ namespace Volo.Abp.SettingManagement
Configuration = configuration; Configuration = configuration;
} }
public Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey) public virtual Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey)
{ {
return Task.FromResult(Configuration[ConfigurationSettingValueProvider.ConfigurationNamePrefix + setting.Name]); return Task.FromResult(Configuration[ConfigurationSettingValueProvider.ConfigurationNamePrefix + setting.Name]);
} }
public Task SetAsync(SettingDefinition setting, string value, string providerKey) public virtual Task SetAsync(SettingDefinition setting, string value, string providerKey)
{ {
throw new AbpException($"Can not set a setting value to the application configuration."); throw new AbpException($"Can not set a setting value to the application configuration.");
} }
public Task ClearAsync(SettingDefinition setting, string providerKey) public virtual Task ClearAsync(SettingDefinition setting, string providerKey)
{ {
throw new AbpException($"Can not set a setting value to the application configuration."); throw new AbpException($"Can not set a setting value to the application configuration.");
} }

@ -8,17 +8,17 @@ namespace Volo.Abp.SettingManagement
{ {
public string Name => DefaultValueSettingValueProvider.ProviderName; public string Name => DefaultValueSettingValueProvider.ProviderName;
public Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey) public virtual Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey)
{ {
return Task.FromResult(setting.DefaultValue); return Task.FromResult(setting.DefaultValue);
} }
public Task SetAsync(SettingDefinition setting, string value, string providerKey) public virtual Task SetAsync(SettingDefinition setting, string value, string providerKey)
{ {
throw new AbpException($"Can not set default value of a setting. It is only possible while defining the setting in a {typeof(ISettingDefinitionProvider)} implementation."); throw new AbpException($"Can not set default value of a setting. It is only possible while defining the setting in a {typeof(ISettingDefinitionProvider)} implementation.");
} }
public Task ClearAsync(SettingDefinition setting, string providerKey) public virtual Task ClearAsync(SettingDefinition setting, string providerKey)
{ {
throw new AbpException($"Can not clear default value of a setting. It is only possible while defining the setting in a {typeof(ISettingDefinitionProvider)} implementation."); throw new AbpException($"Can not clear default value of a setting. It is only possible while defining the setting in a {typeof(ISettingDefinitionProvider)} implementation.");
} }

@ -15,7 +15,7 @@ namespace Volo.Abp.SettingManagement
SettingManagementStore = settingManagementStore; SettingManagementStore = settingManagementStore;
} }
public async Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey) public virtual async Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey)
{ {
return await SettingManagementStore.GetOrNullAsync(setting.Name, Name, NormalizeProviderKey(providerKey)); return await SettingManagementStore.GetOrNullAsync(setting.Name, Name, NormalizeProviderKey(providerKey));
} }

@ -24,13 +24,13 @@ namespace Volo.Abp.SettingManagement
Cache = cache; Cache = cache;
} }
public async Task<string> GetOrNullAsync(string name, string providerName, string providerKey) public virtual async Task<string> GetOrNullAsync(string name, string providerName, string providerKey)
{ {
var cacheItem = await GetCacheItemAsync(name, providerName, providerKey); var cacheItem = await GetCacheItemAsync(name, providerName, providerKey);
return cacheItem.Value; return cacheItem.Value;
} }
public async Task SetAsync(string name, string value, string providerName, string providerKey) public virtual async Task SetAsync(string name, string value, string providerName, string providerKey)
{ {
var setting = await SettingRepository.FindAsync(name, providerName, providerKey); var setting = await SettingRepository.FindAsync(name, providerName, providerKey);
if (setting == null) if (setting == null)
@ -45,13 +45,13 @@ namespace Volo.Abp.SettingManagement
} }
} }
public async Task<List<SettingValue>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<SettingValue>> GetListAsync(string providerName, string providerKey)
{ {
var settings = await SettingRepository.GetListAsync(providerName, providerKey); var settings = await SettingRepository.GetListAsync(providerName, providerKey);
return settings.Select(s => new SettingValue(s.Name, s.Value)).ToList(); return settings.Select(s => new SettingValue(s.Name, s.Value)).ToList();
} }
public async Task DeleteAsync(string name, string providerName, string providerKey) public virtual async Task DeleteAsync(string name, string providerName, string providerKey)
{ {
var setting = await SettingRepository.FindAsync(name, providerName, providerKey); var setting = await SettingRepository.FindAsync(name, providerName, providerKey);
if (setting != null) if (setting != null)

@ -13,7 +13,7 @@ namespace Volo.Abp.SettingManagement
ManagementStore = managementStore; ManagementStore = managementStore;
} }
public Task<string> GetOrNullAsync(string name, string providerName, string providerKey) public virtual Task<string> GetOrNullAsync(string name, string providerName, string providerKey)
{ {
return ManagementStore.GetOrNullAsync(name, providerName, providerKey); return ManagementStore.GetOrNullAsync(name, providerName, providerKey);
} }

@ -15,7 +15,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
{ {
} }
public async Task<Setting> FindAsync(string name, string providerName, string providerKey) public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey)
{ {
return await DbSet return await DbSet
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
@ -23,7 +23,7 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore
); );
} }
public async Task<List<Setting>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<Setting>> GetListAsync(string providerName, string providerKey)
{ {
return await DbSet return await DbSet
.Where( .Where(

@ -16,12 +16,12 @@ namespace Volo.Abp.SettingManagement.MongoDB
} }
public async Task<Setting> FindAsync(string name, string providerName, string providerKey) public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey)
{ {
return await GetMongoQueryable().FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); return await GetMongoQueryable().FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey);
} }
public async Task<List<Setting>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<Setting>> GetListAsync(string providerName, string providerKey)
{ {
return await GetMongoQueryable().Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(); return await GetMongoQueryable().Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync();
} }

@ -12,7 +12,7 @@ namespace Volo.Abp.SettingManagement.Web.Navigation
{ {
public class SettingManagementMainMenuContributor : IMenuContributor public class SettingManagementMainMenuContributor : IMenuContributor
{ {
public async Task ConfigureMenuAsync(MenuConfigurationContext context) public virtual async Task ConfigureMenuAsync(MenuConfigurationContext context)
{ {
if (context.Menu.Name != StandardMenus.Main) if (context.Menu.Name != StandardMenus.Main)
{ {
@ -43,7 +43,7 @@ namespace Volo.Abp.SettingManagement.Web.Navigation
); );
} }
private async Task<bool> CheckAnyOfPagePermissionsGranted( protected virtual async Task<bool> CheckAnyOfPagePermissionsGranted(
SettingManagementPageOptions settingManagementPageOptions, SettingManagementPageOptions settingManagementPageOptions,
SettingPageCreationContext settingPageCreationContext) SettingPageCreationContext settingPageCreationContext)
{ {

@ -9,25 +9,26 @@ namespace Volo.Abp.SettingManagement.Web.Pages.SettingManagement
{ {
public SettingPageCreationContext SettingPageCreationContext { get; private set; } public SettingPageCreationContext SettingPageCreationContext { get; private set; }
private readonly SettingManagementPageOptions _options; protected SettingManagementPageOptions Options { get; }
private readonly IServiceProvider _serviceProvider;
public IndexModel( public IndexModel(IOptions<SettingManagementPageOptions> options)
IOptions<SettingManagementPageOptions> options,
IServiceProvider serviceProvider)
{ {
_serviceProvider = serviceProvider; Options = options.Value;
_options = options.Value;
} }
public async Task OnGetAsync() public virtual async Task OnGetAsync()
{ {
SettingPageCreationContext = new SettingPageCreationContext(_serviceProvider); SettingPageCreationContext = new SettingPageCreationContext(ServiceProvider);
foreach (var contributor in _options.Contributors) foreach (var contributor in Options.Contributors)
{ {
await contributor.ConfigureAsync(SettingPageCreationContext); await contributor.ConfigureAsync(SettingPageCreationContext);
} }
} }
public virtual Task OnPostAsync()
{
return Task.CompletedTask;
}
} }
} }
Loading…
Cancel
Save