LinKit.Sagas
1.2.0
See the version list below for details.
dotnet add package LinKit.Sagas --version 1.2.0
NuGet\Install-Package LinKit.Sagas -Version 1.2.0
<PackageReference Include="LinKit.Sagas" Version="1.2.0" />
<PackageVersion Include="LinKit.Sagas" Version="1.2.0" />
<PackageReference Include="LinKit.Sagas" />
paket add LinKit.Sagas --version 1.2.0
#r "nuget: LinKit.Sagas, 1.2.0"
#:package LinKit.Sagas@1.2.0
#addin nuget:?package=LinKit.Sagas&version=1.2.0
#tool nuget:?package=LinKit.Sagas&version=1.2.0
LinKit.Sagas
LinKit.Sagas provides saga state/step contracts, a coordinator for one explicitly supplied step at a time, and a replaceable repository abstraction.
The default repository is in-memory and volatile. This package does not provide a durable event log, automatic multi-step reverse orchestration, distributed locking, or exactly-once execution.
Install
dotnet add package LinKit.Sagas
Define state and a step
using LinKit.Sagas;
public sealed class CheckoutSagaData : SagaData
{
public Guid OrderId { get; set; }
public bool ReservationCompleted { get; set; }
}
public sealed class ReserveStockStep(IStockService stock) :
ISagaStep<CheckoutSagaData, OrderSubmitted>
{
public async Task ExecuteAsync(
CheckoutSagaData data,
OrderSubmitted message,
CancellationToken cancellationToken = default)
{
await stock.ReserveAsync(message.OrderId, cancellationToken);
data.OrderId = message.OrderId;
data.ReservationCompleted = true;
}
public async Task CompensateAsync(
CheckoutSagaData data,
OrderSubmitted message,
CancellationToken cancellationToken = default)
{
if (data.ReservationCompleted)
{
await stock.ReleaseAsync(data.OrderId, cancellationToken);
data.ReservationCompleted = false;
}
}
}
Register and execute
builder.Services.AddLinKitSagas<CheckoutSagaData>();
builder.Services.AddScoped<ReserveStockStep>();
var app = builder.Build();
var coordinator = app.Services.GetRequiredService<SagaCoordinator<CheckoutSagaData>>();
var step = app.Services.GetRequiredService<ReserveStockStep>();
await coordinator.ExecuteStepAsync(
correlationId,
submittedEvent,
step,
nextState: "StockReserved",
cancellationToken);
The coordinator loads state by correlation ID or creates a new data object, runs the supplied step, updates CurrentState, and saves. If execution throws, it invokes that same step's compensation with a separate bounded token, records a compensated state when possible, and rethrows the original exception.
Production persistence
Register a durable ISagaRepository<TData> implementation before AddLinKitSagas<TData> so the default registration does not replace it. Durable persistence alone does not make a saga operation exactly-once: protect step side effects with idempotency keys, and design recovery for crashes between the remote side effect and the state save. Repository concurrency/versioning, retries, saga history, and compensation-failure recovery are application/provider responsibilities.
Native AOT
The coordinator uses statically typed generic contracts; validate serialization and the concrete repository in the published application. AOT support of a custom persistence provider is outside this package.
License
MIT. See the repository license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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
- LinKit.Core (>= 3.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
-
net8.0
- LinKit.Core (>= 3.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
-
net9.0
- LinKit.Core (>= 3.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.