-
Notifications
You must be signed in to change notification settings - Fork 18
Analyze adding transaction support to Repository #124
Copy link
Copy link
Open
Labels
.NETPull requests that update .NET codePull requests that update .NET codeenhancementNew feature or requestNew feature or requestplanningEnables automatic issue planning with CodeRabbitEnables automatic issue planning with CodeRabbitpriority mediumPlanned enhancement. Queue for upcoming work.Planned enhancement. Queue for upcoming work.questionFurther information is requestedFurther information is requested
Metadata
Metadata
Assignees
Labels
.NETPull requests that update .NET codePull requests that update .NET codeenhancementNew feature or requestNew feature or requestplanningEnables automatic issue planning with CodeRabbitEnables automatic issue planning with CodeRabbitpriority mediumPlanned enhancement. Queue for upcoming work.Planned enhancement. Queue for upcoming work.questionFurther information is requestedFurther information is requested
Problem
The current
Repository<T>callsSaveChangesAsync()individually inside each write method (AddAsync,UpdateAsync,RemoveAsync). This means there is no way to group multiple operations into a single atomic unit — if a multi-step write fails partway through, partial changes are already committed.This is not a current bug (no endpoint today requires multi-step writes), but it becomes relevant if
PATCH(#342), concurrency tokens (#65), or any future feature needs to update more than one entity atomically.Proposed Solution
Expose EF Core's transaction support through the repository layer so callers can opt into atomic multi-step operations when needed, without changing the existing single-operation behavior.
The idiomatic EF Core approach is
DbContext.Database.BeginTransactionAsync()/CommitAsync()/RollbackAsync(). Whether this is surfaced via aUnitOfWorkwrapper, a transaction scope helper on the repository base, or left as aDbContext-level concern passed through the service layer is the design decision this issue should settle before implementation.Suggested Approach
IDbContextTransactiondirectly from aBeginTransactionAsync()method onIRepository<T>UnitOfWorkabstraction that wraps theDbContextand exposesCommitAsync()DbContextlevel inside the service (no repository change)DatabaseFakes.MigrateAsync()) covering commit and rollback paths.Acceptance Criteria
[Trait("Category", "Integration")]andDatabaseFakes.MigrateAsync()CHANGELOG.mdupdatedReferences
Repository<T>andPlayerRepository#461 (repository integration tests — transaction tests belong in the sameIntegration/layer)PATCHmethod for partial updates #342 (PATCH — first feature that could benefit from atomic multi-step writes)