事务性发件箱模式

This commit is contained in:
administrator committed 2025-03-28 22:27:12 +08:00
1 parent 8da853a351
commit f007572e7f
30 files changed
+978 -135

No files matched your search

@@ -0,0 +1,23 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.EntityFrameworkCore;
namespace HelloShop.EventBus.Logging
{
public class ResilientTransaction(DbContext dbContext)
{
public static ResilientTransaction New(DbContext context) => new(context);
public async Task ExecuteAsync(Func<Task> action)
{
var strategy = dbContext.Database.CreateExecutionStrategy();
await strategy.ExecuteAsync(async () =>
{
await using var transaction = await dbContext.Database.BeginTransactionAsync();
await action();
await transaction.CommitAsync();
});
}
}
}