11using System ;
22using System . Threading ;
33using System . Threading . Tasks ;
4- using System . Transactions ;
54using Dotnet6 . GraphQL4 . CrossCutting . Notifications ;
65using Dotnet6 . GraphQL4 . Repositories . Abstractions . DependencyInjection . Options ;
76using Dotnet6 . GraphQL4 . Repositories . Abstractions . Transactions . Extensions ;
@@ -21,46 +20,46 @@ public class UnitOfWork : IUnitOfWork
2120
2221 public UnitOfWork (
2322 DbContext dbContext ,
24- IOptionsMonitor < ApplicationTransactionOptions > optionsMonitor ,
23+ IOptionsSnapshot < ApplicationTransactionOptions > optionsMonitor ,
2524 INotificationContext notificationContext )
2625 {
2726 _dbContext = dbContext ;
28- _options = optionsMonitor . CurrentValue ;
27+ _options = optionsMonitor . Value ;
2928 _database = _dbContext . Database ;
3029 _notificationContext = notificationContext ;
3130 }
3231
33- public TResult ExecuteInTransaction < TResult > ( Func < TResult > operation , Func < bool > condition )
34- => CreateExecutionStrategy ( ) . Execute ( ( ) => ExecuteWithScope ( operation , condition ) ) ;
32+ public TResult ExecuteInTransactionScope < TResult > ( Func < TResult > operation , Func < bool > condition )
33+ => CreateExecutionStrategy ( ) . Execute ( ( ) => ExecuteInScope ( operation , condition ) ) ;
3534
36- public Task < TResult > ExecuteInTransactionAsync < TResult > ( Func < CancellationToken , Task < TResult > > operationAsync , Func < CancellationToken , Task < bool > > condition , CancellationToken cancellationToken )
37- => CreateExecutionStrategy ( ) . ExecuteAsync ( ct => ExecuteWithScopeAsync ( operationAsync , condition , ct ) , cancellationToken ) ;
35+ public Task < TResult > ExecuteInTransactionScopeAsync < TResult > ( Func < CancellationToken , Task < TResult > > operationAsync , Func < CancellationToken , Task < bool > > condition , CancellationToken cancellationToken )
36+ => CreateExecutionStrategy ( ) . ExecuteAsync ( ct => ExecuteInScopeAsync ( operationAsync , condition , ct ) , cancellationToken ) ;
3837
39- private Task < TResult > ExecuteWithScopeAsync < TResult > ( Func < CancellationToken , Task < TResult > > operationAsync , Func < CancellationToken , Task < bool > > condition , CancellationToken cancellationToken )
38+ private Task < TResult > ExecuteInScopeAsync < TResult > ( Func < CancellationToken , Task < TResult > > operationAsync , Func < CancellationToken , Task < bool > > condition , CancellationToken cancellationToken )
4039 => operationAsync
4140 . BeginTransactionScope ( )
42- . WithScopeOption ( TransactionScopeOption . Required )
41+ . WithScopeOption ( )
4342 . WithOptions ( options => options . IsolationLevel = _options . IsolationLevel )
44- . WithScopeAsyncFlowOption ( TransactionScopeAsyncFlowOption . Enabled )
43+ . WithScopeAsyncFlowOption ( )
4544 . WithConditionAsync ( condition ?? ( _ => _notificationContext . AllValidAsync ) )
4645 . ExecuteAsync ( cancellationToken ) ;
4746
48- private TResult ExecuteWithScope < TResult > ( Func < TResult > operation , Func < bool > condition )
47+ private TResult ExecuteInScope < TResult > ( Func < TResult > operation , Func < bool > condition )
4948 => operation
5049 . BeginTransactionScope ( )
51- . WithScopeOption ( TransactionScopeOption . Required )
50+ . WithScopeOption ( )
5251 . WithOptions ( options => options . IsolationLevel = _options . IsolationLevel )
53- . WithScopeAsyncFlowOption ( TransactionScopeAsyncFlowOption . Enabled )
52+ . WithScopeAsyncFlowOption ( )
5453 . WithCondition ( condition ?? ( ( ) => _notificationContext . AllValid ) )
5554 . Execute ( ) ;
5655
5756 private IExecutionStrategy CreateExecutionStrategy ( )
5857 => _database . CreateExecutionStrategy ( ) ;
5958
6059 public bool SaveChanges ( )
61- => _dbContext . SaveChanges ( false ) > default ( int ) ;
60+ => _dbContext . SaveChanges ( false ) > 0 ;
6261
6362 public async Task < bool > SaveChangesAsync ( CancellationToken cancellationToken )
64- => await _dbContext . SaveChangesAsync ( false , cancellationToken ) > default ( int ) ;
63+ => await _dbContext . SaveChangesAsync ( false , cancellationToken ) > 0 ;
6564 }
6665}
0 commit comments