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}。");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
@@ -11,6 +11,12 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Store.Framework\Store.Framework.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- 本模块自己的配置文件:源码里叫 appsettings.json,构建后复制到宿主输出目录时改名为
|
||||
appsettings.CloudProduct.json,避免和宿主自己的 appsettings.json 互相覆盖。
|
||||
由 builder.AddStoreHub() 自动并入宿主配置树(在 appsettings*.json 之后、环境变量之前)。 -->
|
||||
<None Update="appsettings.json" Link="appsettings.CloudProduct.json" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.25" />
|
||||
<PackageReference Include="Hangfire.Dashboard.Basic.Authentication" Version="8.0.0" />
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"Search": {
|
||||
"Url": "http://192.168.0.200:9200",
|
||||
"IndexName": "goods_search"
|
||||
},
|
||||
"RawData": {
|
||||
"Path": "E:\\GoodsRawData"
|
||||
},
|
||||
"Indexing": {
|
||||
"Mode": "Background",
|
||||
"Cron": "*/5 * * * *",
|
||||
"BatchSize": 20000
|
||||
},
|
||||
"Delete": {
|
||||
"SoftDelete": true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user