fix
This commit is contained in:
53
Application/ConfigApplication.cs
Normal file
53
Application/ConfigApplication.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
namespace Application;
|
||||
|
||||
/// <summary>
|
||||
/// 配置应用服务接口
|
||||
/// </summary>
|
||||
public interface IConfigApplication
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取配置值
|
||||
/// </summary>
|
||||
Task<string> GetConfigAsync(string key);
|
||||
|
||||
/// <summary>
|
||||
/// 设置配置值
|
||||
/// </summary>
|
||||
Task SetConfigAsync(string key, string value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置应用服务实现
|
||||
/// </summary>
|
||||
public class ConfigApplication(
|
||||
IConfigService configService,
|
||||
ILogger<ConfigApplication> logger
|
||||
) : IConfigApplication
|
||||
{
|
||||
public async Task<string> GetConfigAsync(string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
throw new ValidationException("配置键不能为空");
|
||||
}
|
||||
|
||||
var value = await configService.GetConfigByKeyAsync<string>(key);
|
||||
return value ?? string.Empty;
|
||||
}
|
||||
|
||||
public async Task SetConfigAsync(string key, string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
throw new ValidationException("配置键不能为空");
|
||||
}
|
||||
|
||||
var success = await configService.SetConfigByKeyAsync(key, value);
|
||||
if (!success)
|
||||
{
|
||||
throw new BusinessException($"设置配置 {key} 失败");
|
||||
}
|
||||
|
||||
logger.LogInformation("配置 {Key} 已更新", key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user