Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Guides & Recipes — Processes

Verified workflow recipes compiled on .NET 10 (ImplicitUsings=disable, Nullable=enable) with EricksonLopez.Processes.Analyzers attached.

using System;
using System.Threading.Tasks;
using EricksonLopez.Processes.Abstractions;
namespace Example.ProcessesQuickStart;
public sealed record InvoiceSagaState(Guid InvoiceId, bool Authorized, bool Captured) : IProcessState;
public sealed record AuthorizeRequested(Guid InvoiceId);
public sealed record CaptureCompleted(Guid InvoiceId);
[SagaDefinition("invoice-settlement")]
public sealed class InvoiceSettlementSaga :
ISaga<InvoiceSagaState>,
IProcessHandler<InvoiceSagaState, AuthorizeRequested>,
IProcessHandler<InvoiceSagaState, CaptureCompleted>
{
public ProcessType Type => ProcessType.From("invoice-settlement");
public ProcessVersion Version => ProcessVersion.Initial;
public ValueTask<ProcessTransitionResult<InvoiceSagaState>> HandleAsync(
InvoiceSagaState state,
AuthorizeRequested eventMessage,
ProcessContext context)
{
var next = state with { InvoiceId = eventMessage.InvoiceId, Authorized = true };
return ValueTask.FromResult(
ProcessTransitionResult<InvoiceSagaState>.Advance(next, ProcessStatus.Running));
}
public ValueTask<ProcessTransitionResult<InvoiceSagaState>> HandleAsync(
InvoiceSagaState state,
CaptureCompleted eventMessage,
ProcessContext context)
{
var done = state with { Captured = true };
return ValueTask.FromResult(ProcessTransitionResult<InvoiceSagaState>.Complete(done));
}
}

Pass [CompensationAction.Create("StepName", payload)] directly to ProcessTransitionResult<TState>.Compensate(state, actions) (do not pass a reason: named argument) and return .Compensated(...) from ICompensationHandler<TState>.CompensateAsync:

using System;
using System.Threading.Tasks;
using EricksonLopez.Processes.Abstractions;
namespace Example.ProcessesQuickStart;
public static class CompensationHelper
{
public static ProcessTransitionResult<OrderSagaState> BeginRollback(OrderSagaState state, Guid orderId)
{
return ProcessTransitionResult<OrderSagaState>.Compensate(
state,
[CompensationAction.Create("ReleaseInventory", orderId)]);
}
}