From a7ec70bc7dbfd2245e66147f1a0bb6522cec9d70 Mon Sep 17 00:00:00 2001 From: mvarendorff Date: Tue, 22 Oct 2024 16:48:50 +0200 Subject: [PATCH] fix: double dispose --- src/Fluss/UnitOfWork/UnitOfWorkFactory.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Fluss/UnitOfWork/UnitOfWorkFactory.cs b/src/Fluss/UnitOfWork/UnitOfWorkFactory.cs index aac3afe..35994c4 100644 --- a/src/Fluss/UnitOfWork/UnitOfWorkFactory.cs +++ b/src/Fluss/UnitOfWork/UnitOfWorkFactory.cs @@ -23,7 +23,8 @@ public async ValueTask Commit(Func action) await RetryPolicy .ExecuteAsync(async () => { - using var unitOfWork = serviceProvider.GetRequiredService(); + using var scope = serviceProvider.CreateScope(); + var unitOfWork = scope.ServiceProvider.GetRequiredService(); await action(unitOfWork); await unitOfWork.CommitInternal(); }); @@ -36,7 +37,8 @@ public async ValueTask Commit(Func> action) return await RetryPolicy .ExecuteAsync(async () => { - using var unitOfWork = serviceProvider.GetRequiredService(); + using var scope = serviceProvider.CreateScope(); + var unitOfWork = scope.ServiceProvider.GetRequiredService(); var result = await action(unitOfWork); await unitOfWork.CommitInternal(); return result;