gx 配置
This commit is contained in:
1 parent
0e1620c1f9
commit
c732ecb1d2
7 files changed
+166
-16
No files matched your search
@@ -21,8 +21,16 @@ namespace Store.Modules.CloudProduct
|
||||
/// </summary>
|
||||
public class CloudProductModule : ModuleBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 本模块自己的配置文件(源码里是 Models/CloudProduct/appsettings.json,
|
||||
/// 构建时复制到宿主输出目录并改名成这个名字,避免与宿主的 appsettings.json 冲突)
|
||||
/// </summary>
|
||||
public const string ConfigurationFileName = "appsettings.CloudProduct.json";
|
||||
|
||||
public override int Priority => IntPriority.Normal;
|
||||
|
||||
public override string? ConfigurationFile => ConfigurationFileName;
|
||||
|
||||
/// <summary>
|
||||
/// 服务注册阶段(builder.Build() 之前):这里只能拿到容器和配置,碰不到 app
|
||||
/// </summary>
|
||||
@@ -31,6 +39,12 @@ namespace Store.Modules.CloudProduct
|
||||
IServiceCollection services = context.Services;
|
||||
IConfiguration configuration = context.Configuration;
|
||||
|
||||
// 本模块的配置节(Search / RawData / Indexing / Delete)都在模块自己的配置文件里,
|
||||
// 关键项缺失直接报错,避免 OpenSearch 地址为空、原始数据写到意外目录之类的隐性故障
|
||||
RequireConfiguration(configuration, "Search:Url");
|
||||
RequireConfiguration(configuration, "Search:IndexName");
|
||||
RequireConfiguration(configuration, "RawData:Path");
|
||||
|
||||
// ===== Hangfire 后台定时任务(商品分词同步) =====
|
||||
var hangfireConnection = configuration.GetConnectionString("DefaultConnection")
|
||||
?? throw new InvalidOperationException("缺少配置 ConnectionStrings:DefaultConnection,CloudProduct 模块的 Hangfire 无法启动。");
|
||||
@@ -85,5 +99,16 @@ namespace Store.Modules.CloudProduct
|
||||
Console.WriteLine("[Hangfire] 看板/定时任务装配失败: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 校验模块配置项存在(值来自模块自己的 <see cref="ConfigurationFileName"/>)
|
||||
/// </summary>
|
||||
private static void RequireConfiguration(IConfiguration configuration, string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(configuration.GetValue<string>(key)))
|
||||
{
|
||||
throw new InvalidOperationException($"缺少配置 {key},请检查模块配置文件 {ConfigurationFileName}。");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user