File tree Expand file tree Collapse file tree 4 files changed +8
-8
lines changed
CodeOfChaos.Types.UnitOfWork.Contracts
CodeOfChaos.Types.UnitOfWork
tests/Tests.CodeOfChaos.Types.UnitOfWork Expand file tree Collapse file tree 4 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -20,5 +20,5 @@ public interface IUnitOfWork : IAsyncDisposable {
2020
2121 ValueTask < TDbContext > GetDbContextAsync < TDbContext > ( CancellationToken ct = default ) where TDbContext : DbContext ;
2222
23- TRepo GetRepository < TRepo > ( ) where TRepo : class , IToUnitOfWorkRepository ;
23+ TRepo GetRepository < TRepo > ( ) where TRepo : class , IUnitOfWorkRepository ;
2424}
Original file line number Diff line number Diff line change @@ -5,4 +5,4 @@ namespace CodeOfChaos.Types.UnitOfWork;
55// ---------------------------------------------------------------------------------------------------------------------
66// Code
77// ---------------------------------------------------------------------------------------------------------------------
8- public interface IToUnitOfWorkRepository ;
8+ public interface IUnitOfWorkRepository ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ namespace CodeOfChaos.Types.UnitOfWork;
1414public class UnitOfWork < TDbContext > ( IDbContextFactory < TDbContext > dbContextFactory , IServiceScope serviceScope ) : IUnitOfWork where TDbContext : DbContext {
1515 private readonly AsyncLazy < TDbContext > _db = new ( async ct => await dbContextFactory . CreateDbContextAsync ( ct ) ) ;
1616 private IDbContextTransaction ? _transaction ;
17- private ConcurrentDictionary < Type , IToUnitOfWorkRepository > AttachedRepositories { get ; } = [ ] ;
17+ private ConcurrentDictionary < Type , IUnitOfWorkRepository > AttachedRepositories { get ; } = [ ] ;
1818
1919 // -----------------------------------------------------------------------------------------------------------------
2020 // Methods
@@ -84,8 +84,8 @@ public virtual async ValueTask<T> GetDbContextAsync<T>(CancellationToken ct = de
8484 return dbContext as T ?? throw new InvalidCastException ( $ "Cannot cast DbContext of type '{ dbContext . GetType ( ) } ' to '{ typeof ( T ) } '") ;
8585 }
8686
87- public virtual TRepo GetRepository < TRepo > ( ) where TRepo : class , IToUnitOfWorkRepository {
88- if ( AttachedRepositories . TryGetValue ( typeof ( TRepo ) , out IToUnitOfWorkRepository ? cachedRepo ) && cachedRepo is TRepo castedCachedRepo ) return castedCachedRepo ;
87+ public virtual TRepo GetRepository < TRepo > ( ) where TRepo : class , IUnitOfWorkRepository {
88+ if ( AttachedRepositories . TryGetValue ( typeof ( TRepo ) , out IUnitOfWorkRepository ? cachedRepo ) && cachedRepo is TRepo castedCachedRepo ) return castedCachedRepo ;
8989
9090 // Cache miss so we create a new instance
9191 var repo = serviceScope . ServiceProvider . GetRequiredService < TRepo > ( ) ;
Original file line number Diff line number Diff line change @@ -193,14 +193,14 @@ public async Task GetDbContextAsync_ShouldThrowForUnsupportedDbContextType() {
193193 [ Test ]
194194 public async Task GetRepository_ShouldRetrieveRepositoryFromServiceProvider ( ) {
195195 // Arrange
196- var mockRepository = new Mock < IToUnitOfWorkRepository > ( ) ;
196+ var mockRepository = new Mock < IUnitOfWorkRepository > ( ) ;
197197 _serviceProvider
198- . Setup ( sp => sp . GetService ( typeof ( IToUnitOfWorkRepository ) ) )
198+ . Setup ( sp => sp . GetService ( typeof ( IUnitOfWorkRepository ) ) )
199199 . Returns ( mockRepository . Object ) ;
200200
201201
202202 // Act
203- var repository = _unitOfWork . GetRepository < IToUnitOfWorkRepository > ( ) ;
203+ var repository = _unitOfWork . GetRepository < IUnitOfWorkRepository > ( ) ;
204204
205205 // Assert
206206 await Assert . That ( repository ) . IsNotNull ( ) ;
You can’t perform that action at this time.
0 commit comments