33using System . Threading . Tasks ;
44using System . Transactions ;
55using Dotnet6 . GraphQL4 . CrossCutting . Notifications ;
6- using Dotnet6 . GraphQL4 . Repositories . Abstractions . DependencyInjection ;
6+ using Dotnet6 . GraphQL4 . Repositories . Abstractions . DependencyInjection . Options ;
77using Dotnet6 . GraphQL4 . Repositories . Abstractions . Transactions . Extensions ;
88using Microsoft . EntityFrameworkCore ;
99using Microsoft . EntityFrameworkCore . Infrastructure ;
@@ -16,13 +16,16 @@ public class UnitOfWork : IUnitOfWork
1616 {
1717 private readonly DatabaseFacade _database ;
1818 private readonly DbContext _dbContext ;
19- private readonly IOptionsMonitor < ApplicationTransactionOptions > _options ;
19+ private readonly ApplicationTransactionOptions _options ;
2020 private readonly INotificationContext _notificationContext ;
2121
22- public UnitOfWork ( DbContext dbContext , IOptionsMonitor < ApplicationTransactionOptions > options , INotificationContext notificationContext )
22+ public UnitOfWork (
23+ DbContext dbContext ,
24+ IOptionsMonitor < ApplicationTransactionOptions > optionsMonitor ,
25+ INotificationContext notificationContext )
2326 {
2427 _dbContext = dbContext ;
25- _options = options ;
28+ _options = optionsMonitor . CurrentValue ;
2629 _database = _dbContext . Database ;
2730 _notificationContext = notificationContext ;
2831 }
@@ -35,18 +38,18 @@ public Task<TResult> ExecuteInTransactionAsync<TResult>(Func<CancellationToken,
3538
3639 private Task < TResult > ExecuteWithScopeAsync < TResult > ( Func < CancellationToken , Task < TResult > > operationAsync , Func < CancellationToken , Task < bool > > condition , CancellationToken cancellationToken )
3740 => operationAsync
38- . TransactionAsync ( )
41+ . BeginTransactionScope ( )
3942 . WithScopeOption ( TransactionScopeOption . Required )
40- . WithOptions ( options => options . IsolationLevel = _options . CurrentValue . IsolationLevel )
43+ . WithOptions ( options => options . IsolationLevel = _options . IsolationLevel )
4144 . WithScopeAsyncFlowOption ( TransactionScopeAsyncFlowOption . Enabled )
4245 . WithConditionAsync ( condition ?? ( _ => _notificationContext . AllValidAsync ) )
4346 . ExecuteAsync ( cancellationToken ) ;
4447
4548 private TResult ExecuteWithScope < TResult > ( Func < TResult > operation , Func < bool > condition )
4649 => operation
47- . Transaction ( )
50+ . BeginTransactionScope ( )
4851 . WithScopeOption ( TransactionScopeOption . Required )
49- . WithOptions ( options => options . IsolationLevel = _options . CurrentValue . IsolationLevel )
52+ . WithOptions ( options => options . IsolationLevel = _options . IsolationLevel )
5053 . WithScopeAsyncFlowOption ( TransactionScopeAsyncFlowOption . Enabled )
5154 . WithCondition ( condition ?? ( ( ) => _notificationContext . AllValid ) )
5255 . Execute ( ) ;
@@ -55,9 +58,9 @@ private IExecutionStrategy CreateExecutionStrategy()
5558 => _database . CreateExecutionStrategy ( ) ;
5659
5760 public bool SaveChanges ( )
58- => _dbContext . SaveChanges ( true ) > default ( int ) ;
61+ => _dbContext . SaveChanges ( false ) > default ( int ) ;
5962
6063 public async Task < bool > SaveChangesAsync ( CancellationToken cancellationToken )
61- => await _dbContext . SaveChangesAsync ( true , cancellationToken ) > default ( int ) ;
64+ => await _dbContext . SaveChangesAsync ( false , cancellationToken ) > default ( int ) ;
6265 }
6366}
0 commit comments