fix(transaction): retain both transaction failures
Keep the original action or commit failure visible alongside a failed rollback and cover owned transaction reuse. Ref: IT-1588
This commit is contained in:
@@ -4,12 +4,13 @@ Reusable Entity Framework Core base library for HrynCo applications.
|
||||
|
||||
## Solution
|
||||
|
||||
The solution (`hrynco-ef.slnx`) contains two projects:
|
||||
The solution (`hrynco-ef.slnx`) contains the following projects:
|
||||
|
||||
| Project | Description |
|
||||
|---|---|
|
||||
| `HrynCo.DAL.Abstract` | Infrastructure-agnostic contracts: entities, repository interfaces, unit of work, transactions, pagination. No EF Core dependency. |
|
||||
| `HrynCo.DAL.EF` | Entity Framework Core implementations of the abstract contracts. Depends on `HrynCo.DAL.Abstract` and EF Core. |
|
||||
| `HrynCo.DAL.EF.Tests` | Transaction lifecycle regression tests using SQLite in memory. |
|
||||
|
||||
The split allows consuming projects to reference only `HrynCo.DAL.Abstract` in domain/application layers, keeping those layers free of EF Core.
|
||||
|
||||
@@ -181,6 +182,18 @@ Entity Framework Core implementations of the abstract contracts.
|
||||
|
||||
## Usage
|
||||
|
||||
### Transaction ownership and failures
|
||||
|
||||
Both `ExecuteInTransactionAsync` overloads create, commit, and dispose a transaction when no transaction is already cached by the unit of work. After disposal, the cached reference is cleared, so a later call starts a fresh transaction.
|
||||
|
||||
If the action or commit fails, the owned transaction is rolled back. If rollback also fails (including when the provider reports a completed transaction), an `AggregateException` contains the original failure first and the rollback failure second. Disposal still runs.
|
||||
|
||||
When `BeginTransactionAsync` has already supplied a transaction to the caller, `ExecuteInTransactionAsync` runs the action inside that transaction and leaves commit, rollback, and disposal to the caller. Its cached reference is retained as before; the automatic cleanup above applies only to transactions owned by `ExecuteInTransactionAsync`.
|
||||
|
||||
Run the regression suite with `dotnet test hrynco-ef.slnx`.
|
||||
|
||||
### Package references
|
||||
|
||||
Reference `HrynCo.DAL.Abstract` for contracts only (e.g. in domain/application layers).
|
||||
Reference `HrynCo.DAL.EF` for the full EF Core implementation (infrastructure layer).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user