ghts.Saga.Compensator
1.0.6
dotnet add package ghts.Saga.Compensator --version 1.0.6
NuGet\Install-Package ghts.Saga.Compensator -Version 1.0.6
<PackageReference Include="ghts.Saga.Compensator" Version="1.0.6" />
<PackageVersion Include="ghts.Saga.Compensator" Version="1.0.6" />
<PackageReference Include="ghts.Saga.Compensator" />
paket add ghts.Saga.Compensator --version 1.0.6
#r "nuget: ghts.Saga.Compensator, 1.0.6"
#:package ghts.Saga.Compensator@1.0.6
#addin nuget:?package=ghts.Saga.Compensator&version=1.0.6
#tool nuget:?package=ghts.Saga.Compensator&version=1.0.6
SagaCompensator
What is SagaCompensator?
SagaCompensator is a lightweight .NET library that provides an in-memory orchestrator for managing compensating transactions in distributed workflows based on the Saga pattern.
When a saga step fails, all previously completed steps must be undone in reverse order. SagaCompensator handles this automatically using a LIFO (last-in, first-out) stack internally, ensuring that compensations are always executed in the correct order without any manual coordination.
It integrates natively with the .NET dependency injection system and supports structured logging through Microsoft.Extensions.Logging.
Key Concepts
Saga Pattern
A saga is a sequence of local transactions, each belonging to a different service or bounded context. If any step fails, the saga triggers compensating transactions for all previously succeeded steps to restore consistency.
Compensation
A compensation is the business-level "undo" operation for a completed step. It is not a technical database rollback — it is a new forward action that reverses the observable effect of a previous one (for example, cancelling a reservation that was already confirmed, or issuing a refund for a charge already processed).
Orchestrator
In an orchestrated saga, a central coordinator controls the flow: it calls each step in sequence and decides what to do on success or failure. SagaCompensator integrates into this coordinator layer, providing it with the tooling needed to register, track, and execute compensations cleanly.
How It Works
- Before executing the saga, you obtain an
ISagaOrchestratorinstance (via dependency injection or directly). - As each step completes successfully, you register its corresponding compensation action using
AddCompensationor automatically viaExecuteStepAsync. - If any step fails, you call
RollbackAsync()and the library executes all registered compensations in reverse order. - If a compensation itself throws an error, it is logged and execution continues with the remaining compensations — ensuring the rollback process is always completed.
RollbackAsync()is idempotent: calling it multiple times has no additional effect.
Installation
SagaCompensator is distributed as a NuGet package targeting .NET 10.0.
.NET CLI
dotnet add package SagaCompensator
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.6 | 112 | 4/27/2026 |