You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB
C#

using NPin.Framework.SettingManagement.Domain.Provider;
using NPin.Framework.SettingManagement.Domain.Store;
using Volo.Abp.Settings;
namespace NPin.Framework.SettingManagement.Domain;
/// <summary>
/// 设置管理器提供者
/// </summary>
public abstract class SettingManagementProvider : ISettingManagementProvider
{
public abstract string Name { get; }
protected ISettingManagementStore SettingManagementStore { get; }
public SettingManagementProvider(ISettingManagementStore settingManagementStore)
{
SettingManagementStore = settingManagementStore;
}
public virtual async Task<string?> GetOrNullAsync(SettingDefinition setting, string? providerKey)
{
return await SettingManagementStore.GetOrNullAsync(setting.Name, Name, NormalizeProviderKey(providerKey));
}
public virtual async Task<List<SettingValue>> GetByPrefixAsync(string prefix, string? providerKey)
{
return await SettingManagementStore.GetListByPrefixAsync(prefix, Name, NormalizeProviderKey(providerKey));
}
public virtual async Task SetAsync(SettingDefinition setting, string value, string? providerKey)
{
await SettingManagementStore.SetAsync(setting.Name, value, Name, NormalizeProviderKey(providerKey));
}
public virtual async Task ClearAsync(SettingDefinition setting, string? providerKey)
{
await SettingManagementStore.DeleteAsync(setting.Name, Name, NormalizeProviderKey(providerKey));
}
protected virtual string? NormalizeProviderKey(string? providerKey)
{
return providerKey;
}
}