@@ -11,18 +11,14 @@ internal class Repository<TDbContext> : RepositoryBase
1111 return entity ;
1212 } ) ;
1313
14- private readonly TransactionOptions _transactionOptions ;
15- private readonly TransactionScopeOption _transactionScopeOption ;
16- private readonly IDbContextFactory < TDbContext > _dbContextFactory ;
14+ //private readonly TransactionOptions transactionOptions;
15+ //private readonly TransactionScopeOption transactionScopeOption;
1716
18- public Repository ( IDbContextFactory < TDbContext > dbContextFactory
19- , TransactionScopeOption transactionScopeOption
20- , System . Transactions . IsolationLevel isolationLevel )
21- : base ( dbContextFactory . CreateDbContext ( ) )
17+ public Repository ( TDbContext dbContext /*, TransactionScopeOption transactionScopeOption, System.Transactions.IsolationLevel isolationLevel*/ )
18+ : base ( dbContext )
2219 {
23- this . _transactionScopeOption = transactionScopeOption ;
24- this . _dbContextFactory = dbContextFactory ;
25- this . _transactionOptions = new ( ) { IsolationLevel = isolationLevel } ;
20+ //this.transactionScopeOption = transactionScopeOption;
21+ //this.transactionOptions = new() { IsolationLevel = isolationLevel };
2622 }
2723
2824 public IQueryable < T > AsQueryable < T > ( ) where T : class
@@ -32,7 +28,7 @@ public IQueryable<T> AsQueryable<T>() where T : class
3228
3329 private DbSet < T > CachedContextSet < T > ( ) where T : class
3430 {
35- return ( DbSet < T > ) _cachedDbSets . GetOrAdd ( typeof ( T ) . FullName , DbContext . Set < T > ( ) ) ;
31+ return ( DbSet < T > ) _cachedDbSets . GetOrAdd ( typeof ( T ) . FullName , CurrentDbContext . Set < T > ( ) ) ;
3632 }
3733
3834 public void Delete < T > ( T entity ) where T : class
@@ -60,44 +56,44 @@ public void Delete<T>(IEnumerable<T> entities) where T : class
6056 {
6157 ArgumentNullException . ThrowIfNull ( keyValues , nameof ( keyValues ) ) ;
6258
63- using ( CreateTransactionScope ( ) )
64- return CachedContextSet < T > ( ) . Find ( keyValues ) ;
59+ // using (CreateTransactionScope())
60+ return CachedContextSet < T > ( ) . Find ( keyValues ) ;
6561 }
6662
6763 public ValueTask < T ? > FindAsync < T > ( object [ ] keyValues , CancellationToken cancellationToken = default ) where T : class
6864 {
6965 ArgumentNullException . ThrowIfNull ( keyValues , nameof ( keyValues ) ) ;
7066
71- using ( CreateTransactionScope ( ) )
72- return CachedContextSet < T > ( ) . FindAsync ( keyValues , cancellationToken ) ;
67+ // using (CreateTransactionScope())
68+ return CachedContextSet < T > ( ) . FindAsync ( keyValues , cancellationToken ) ;
7369 }
7470
7571 public T ? FirstOrDefault < T > ( Expression < Func < T , bool > > predicate ) where T : class
7672 {
7773 ArgumentNullException . ThrowIfNull ( predicate , nameof ( predicate ) ) ;
7874
79- using ( CreateTransactionScope ( ) )
80- return AsQueryable < T > ( ) . FirstOrDefault ( predicate ) ;
75+ // using (CreateTransactionScope())
76+ return AsQueryable < T > ( ) . FirstOrDefault ( predicate ) ;
8177 }
8278
8379 public T ? FirstOrDefault < T > ( ) where T : class
8480 {
85- using ( CreateTransactionScope ( ) )
86- return AsQueryable < T > ( ) . FirstOrDefault ( ) ;
81+ // using (CreateTransactionScope())
82+ return AsQueryable < T > ( ) . FirstOrDefault ( ) ;
8783 }
8884
8985 public Task < T ? > FirstOrDefaultAsync < T > ( Expression < Func < T , bool > > predicate , CancellationToken cancellationToken = default ) where T : class
9086 {
9187 ArgumentNullException . ThrowIfNull ( predicate , nameof ( predicate ) ) ;
9288
93- using ( CreateTransactionScope ( ) )
94- return AsQueryable < T > ( ) . FirstOrDefaultAsync ( predicate , cancellationToken ) ;
89+ // using (CreateTransactionScope())
90+ return AsQueryable < T > ( ) . FirstOrDefaultAsync ( predicate , cancellationToken ) ;
9591 }
9692
9793 public Task < T ? > FirstOrDefaultAsync < T > ( CancellationToken cancellationToken = default ) where T : class
9894 {
99- using ( CreateTransactionScope ( ) )
100- return AsQueryable < T > ( ) . FirstOrDefaultAsync ( cancellationToken ) ;
95+ // using (CreateTransactionScope())
96+ return AsQueryable < T > ( ) . FirstOrDefaultAsync ( cancellationToken ) ;
10197 }
10298
10399 public T ? GetById < T > ( object id ) where T : class
@@ -165,8 +161,8 @@ public Task<List<T>> WhereWithTransactionScopeAsync<T>(Expression<Func<T, bool>>
165161 {
166162 ArgumentNullException . ThrowIfNull ( predicate , nameof ( predicate ) ) ;
167163
168- using ( CreateTransactionScope ( ) )
169- return AsQueryable < T > ( ) . Where ( predicate ) . ToListAsync ( ) ;
164+ // using (CreateTransactionScope())
165+ return AsQueryable < T > ( ) . Where ( predicate ) . ToListAsync ( ) ;
170166 }
171167
172168 private void _InternalInsert < T > ( IEnumerable < T > entities ) where T : class
@@ -183,15 +179,10 @@ private Task _InternalInsertAsync<T>(IEnumerable<T> entities, CancellationToken
183179 return CachedContextSet < T > ( ) . AddRangeAsync ( entities . Select ( f => ( T ) _funcCreatedAt ( f ) ) , cancellationToken ) ;
184180 }
185181
186- private TransactionScope CreateTransactionScope ( )
187- {
188- TransactionScopeAsyncFlowOption transactionScopeAsyncFlowOption =
189- _transactionScopeOption == TransactionScopeOption . Suppress ? TransactionScopeAsyncFlowOption . Suppress : TransactionScopeAsyncFlowOption . Enabled ;
190- return new TransactionScope ( _transactionScopeOption , _transactionOptions , transactionScopeAsyncFlowOption ) ;
191- }
192-
193- public override DbContext CreateDbContext ( )
194- {
195- return _dbContextFactory . CreateDbContext ( ) ;
196- }
182+ //private TransactionScope CreateTransactionScope()
183+ //{
184+ // TransactionScopeAsyncFlowOption transactionScopeAsyncFlowOption =
185+ // transactionScopeOption == TransactionScopeOption.Suppress ? TransactionScopeAsyncFlowOption.Suppress : TransactionScopeAsyncFlowOption.Suppress;
186+ // return new TransactionScope(transactionScopeOption, transactionOptions, transactionScopeAsyncFlowOption);
187+ //}
197188}
0 commit comments