Skip to content

Feature 025: Transaction Manager Pattern (renamed from Unit of Work)#29

Merged
ovation22 merged 5 commits intomainfrom
feature/025-unit-of-work-pattern
Jan 27, 2026
Merged

Feature 025: Transaction Manager Pattern (renamed from Unit of Work)#29
ovation22 merged 5 commits intomainfrom
feature/025-unit-of-work-pattern

Conversation

@ovation22
Copy link
Copy Markdown
Owner

Summary

Implements explicit transaction management for repository operations, replacing the old ExecuteInTransactionAsync repository methods. After implementation, renamed from IUnitOfWork to ITransactionManager for accuracy since this manages transaction boundaries rather than implementing a true Unit of Work pattern.

Changes

Core Implementation

  • ITransactionManager interface with transaction lifecycle methods:
    • BeginTransactionAsync, CommitAsync, RollbackAsync for manual control
    • ExecuteAsync convenience wrappers for automatic commit/rollback
  • TransactionManager implementation wrapping EF Core transactions
  • 8 comprehensive unit tests using SQLite in-memory database

Integration

  • Registered ITransactionManager in all 5 applications (4 microservices + API)
  • Migrated 3 request processors (Breeding, Training, Feeding) to use ITransactionManager
  • Added DbContext DI registration to satisfy TransactionManager dependency

Cleanup

  • Removed ExecuteInTransactionAsync from IEFRepository interface and EFRepository implementation
  • All code references eliminated (only doc files remain)

Technical 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"?

  • True UoW defers all saves until commit
  • Our repositories auto-save, TransactionManager wraps transaction boundaries
  • Name accurately describes functionality

DI Pattern: Uses factory registration for DbContext → TripleDerbyContext mapping to allow generic DbContext injection.

Test Results

  • ✅ All 763 tests passing
  • ✅ No behavioral changes
  • ✅ Successful compilation across all projects

Files Changed

  • New: ITransactionManager, TransactionManager, TransactionManagerTests
  • Modified: 5 DI configurations, 3 request processors, test files
  • Removed: ExecuteInTransactionAsync methods from repository layer
  • Docs: Feature 024 (season/career progression) included

🤖 Generated with Claude Code

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.
@github-actions
Copy link
Copy Markdown

Test Results

717 tests  +8   717 ✅ +8   4s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 8166a68. ± Comparison against base commit 12778c8.

@ovation22 ovation22 merged commit a52cd63 into main Jan 27, 2026
2 checks passed
@ovation22 ovation22 deleted the feature/025-unit-of-work-pattern branch January 27, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant