From a87ebeaffbed0e390e0656b1fb690c35f6052c52 Mon Sep 17 00:00:00 2001 From: chfei Date: Fri, 23 Oct 2026 16:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Hangfire=20mysql=20?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugins/CloudProduct/CloudProductPlugin.cs | 9 ++++----- Plugins/CloudProduct/Store.CloudProduct.csproj | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Plugins/CloudProduct/CloudProductPlugin.cs b/Plugins/CloudProduct/CloudProductPlugin.cs index 7c4519a..a44b4b6 100644 --- a/Plugins/CloudProduct/CloudProductPlugin.cs +++ b/Plugins/CloudProduct/CloudProductPlugin.cs @@ -26,22 +26,21 @@ namespace Store.Modules.CloudProduct var hangfireConnection = configuration.GetValue("CloudProductConnection") ?? throw new InvalidOperationException("缺少配置 CloudProductConnection,CloudProduct 模块的 Hangfire 无法启动。"); - // AllowUserVariables=true:Hangfire.MySqlStorage 的建表/查询语句依赖用户变量 + // 存储中的建表/查询语句依赖用户变量;与业务仓储共用 FreeSql。 var connectionStringBuilder = new MySqlConnectionStringBuilder(hangfireConnection) { AllowUserVariables = true }; - services.AddHangfire(config => config + services.AddHangfire((provider, config) => config .SetDataCompatibilityLevel(CompatibilityLevel.Version_180) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() - .UseStorage(new MySqlStorage(connectionStringBuilder.ConnectionString, new MySqlStorageOptions() { TablesPrefix = "Hangfire_" }))); + .UseStorage(new MySqlStorage(provider.GetRequiredKeyedService("CloudProductConnection"), new MySqlStorageOptions() { TablesPrefix = "Hangfire_" }))); services.AddHangfireServer(); services.AddTransient(); - var connection = RequireConfiguration("CloudProductConnection"); services.AddKeyedSingleton("CloudProductConnection", (_, _) => - new FreeSql.FreeSqlBuilder().UseConnectionString(FreeSql.DataType.MySql, connection) + new FreeSql.FreeSqlBuilder().UseConnectionString(FreeSql.DataType.MySql, connectionStringBuilder.ConnectionString) .UseAdoConnectionPool(true).Build()); services.AddHostedService(); diff --git a/Plugins/CloudProduct/Store.CloudProduct.csproj b/Plugins/CloudProduct/Store.CloudProduct.csproj index 5e16d8d..27459a0 100644 --- a/Plugins/CloudProduct/Store.CloudProduct.csproj +++ b/Plugins/CloudProduct/Store.CloudProduct.csproj @@ -4,6 +4,8 @@ true enable enable + zh-Hans;zh-Hant;zh;en + @@ -23,12 +25,10 @@ - + - -