diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs index b74e5076b..cdca0c478 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs @@ -61,7 +61,7 @@ public static IHostApplicationBuilder AddHangfire(this IHostApplicationBuilder b .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() - .UsePostgreSqlStorage(o => o.UseExistingNpgsqlConnection(sp.GetRequiredService().CreateConnection()))); + .UsePostgreSqlStorage(o => o.UseConnectionFactory(new DbDataSourceConnectionFactory(sp.GetRequiredService())))); } return builder; @@ -94,4 +94,9 @@ public static string GetPostgresConnectionString(this IConfiguration configurati // We rely on error details to get the offending duplicate key values in the TrsDataSyncHelper IncludeErrorDetail = true }.ConnectionString; + + private class DbDataSourceConnectionFactory(NpgsqlDataSource dataSource) : IConnectionFactory + { + public NpgsqlConnection GetOrCreateConnection() => dataSource.CreateConnection(); + } }