更新 Hangfire mysql 包
This commit is contained in:
1 parent
96fed35907
commit
a87ebeaffb
2 files changed
+7
-8
No files matched your search
@@ -26,22 +26,21 @@ namespace Store.Modules.CloudProduct
|
||||
var hangfireConnection = configuration.GetValue<string>("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<IFreeSql>("CloudProductConnection"), new MySqlStorageOptions() { TablesPrefix = "Hangfire_" })));
|
||||
services.AddHangfireServer();
|
||||
services.AddTransient<GoodsIndexJob>();
|
||||
var connection = RequireConfiguration("CloudProductConnection");
|
||||
services.AddKeyedSingleton<IFreeSql>("CloudProductConnection", (_, _) =>
|
||||
new FreeSql.FreeSqlBuilder().UseConnectionString(FreeSql.DataType.MySql, connection)
|
||||
new FreeSql.FreeSqlBuilder().UseConnectionString(FreeSql.DataType.MySql, connectionStringBuilder.ConnectionString)
|
||||
.UseAdoConnectionPool(true).Build());
|
||||
services.AddHostedService<CloudProductSearchStartup>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user