Feature 025: Transaction Manager Pattern (renamed from Unit of Work)#29
Merged
Feature 025: Transaction Manager Pattern (renamed from Unit of Work)#29
Conversation
Create IUnitOfWork abstraction to manage database transactions explicitly, separating transaction control from repository data access operations. Changes: - Add IUnitOfWork interface with transaction lifecycle methods - Implement UnitOfWork class wrapping EF Core transaction management - Add comprehensive unit tests using SQLite in-memory for real transaction testing - Add SQLite package to test project for transaction support - Update UnitOfWork constructor to accept DbContext for better testability Files created: - TripleDerby.Core/Abstractions/Data/IUnitOfWork.cs - TripleDerby.Infrastructure/Data/UnitOfWork.cs - TripleDerby.Tests.Unit/Infrastructure/Data/UnitOfWorkTests.cs Files modified: - TripleDerby.Tests.Unit/TripleDerby.Tests.Unit.csproj Related to feature #25: Unit of Work Pattern
Add IUnitOfWork registration to all 4 microservices and the API, making the Unit of Work infrastructure available for dependency injection. Changes: - Register IUnitOfWork in Breeding microservice - Register IUnitOfWork in Training microservice - Register IUnitOfWork in Feeding microservice - Register IUnitOfWork in Racing microservice - Register IUnitOfWork in API via DatabaseConfig - Add using statement for TripleDerby.Core.Abstractions.Data in all applications All services now have IUnitOfWork available as a scoped dependency, ready for use in request processors. Related to feature #25: Unit of Work Pattern - Phase 2 complete
Migrated all three request processors (Breeding, Training, Feeding) to use the new IUnitOfWork pattern instead of repository.ExecuteInTransactionAsync. This improves separation of concerns by moving transaction management out of the repository layer. Changes: - Updated BreedingRequestProcessor to inject and use IUnitOfWork - Updated TrainingRequestProcessor to inject and use IUnitOfWork - Updated FeedingRequestProcessor to inject and use IUnitOfWork - Fixed BreedingRequestProcessorTests to include IUnitOfWork mock parameter - Fixed UnitOfWorkTests rollback test by clearing EF change tracker All 763 tests passing. Transaction behavior unchanged.
Removed the ExecuteInTransactionAsync methods from both the IEFRepository interface and EFRepository implementation. Transaction management is now handled exclusively by IUnitOfWork, achieving better separation of concerns and cleaner architecture. Changes: - Removed ExecuteInTransactionAsync(Func<Task>) from IEFRepository - Removed ExecuteInTransactionAsync<T>(Func<Task<T>>) from IEFRepository - Removed both method implementations from EFRepository - Removed all associated XML documentation All 763 tests passing. Grep confirms no code references remain (only docs). Unit of Work pattern migration complete.
The pattern implemented is a transaction manager, not a true Unit of Work. Repository methods continue to save immediately; this manages transaction boundaries around groups of operations. Renamed for clarity and accuracy. Changes: - IUnitOfWork → ITransactionManager - UnitOfWork → TransactionManager - UnitOfWorkTests → TransactionManagerTests - Updated all usages in processors, tests, and DI registrations - Variable names: unitOfWork → transactionManager - Added clarity in XML documentation about separation of concerns Also includes Feature 024 documentation (season/career progression). All 763 tests passing. No behavior changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements explicit transaction management for repository operations, replacing the old
ExecuteInTransactionAsyncrepository methods. After implementation, renamed fromIUnitOfWorktoITransactionManagerfor accuracy since this manages transaction boundaries rather than implementing a true Unit of Work pattern.Changes
Core Implementation
BeginTransactionAsync,CommitAsync,RollbackAsyncfor manual controlExecuteAsyncconvenience wrappers for automatic commit/rollbackIntegration
DbContextDI registration to satisfy TransactionManager dependencyCleanup
ExecuteInTransactionAsyncfrom IEFRepository interface and EFRepository implementationTechnical Details
Architecture: Repository methods continue to save immediately; TransactionManager provides transaction boundaries around groups of operations. This separates transaction control from data access.
Why "TransactionManager" not "UnitOfWork"?
DI Pattern: Uses factory registration for DbContext → TripleDerbyContext mapping to allow generic DbContext injection.
Test Results
Files Changed
🤖 Generated with Claude Code