Table of Contents

Class PersistenceMiddleware

Namespace
WorkflowForge.Extensions.Persistence
Assembly
WorkflowForge.Extensions.Persistence.dll

Persists and resumes workflow execution by checkpointing after each operation via a user-provided provider. Uses an index-based counter to track the current operation position. The counter is stored on foundry.Properties and incremented after each operation completes, making it O(1) per operation with no dictionary lookups. Safe for nested workflows because each foundry has its own property dictionary.

public sealed class PersistenceMiddleware : IWorkflowOperationMiddleware
Inheritance
PersistenceMiddleware
Implements
Inherited Members

Constructors

PersistenceMiddleware(IWorkflowPersistenceProvider)

Initializes a new instance of the PersistenceMiddleware class.

public PersistenceMiddleware(IWorkflowPersistenceProvider provider)

Parameters

provider IWorkflowPersistenceProvider

The persistence provider that saves, loads, and deletes workflow snapshots.

Exceptions

ArgumentNullException

Thrown when provider is null.

PersistenceMiddleware(IWorkflowPersistenceProvider, PersistenceOptions)

Initializes a new instance of the PersistenceMiddleware class with options for stable keys.

public PersistenceMiddleware(IWorkflowPersistenceProvider provider, PersistenceOptions options)

Parameters

provider IWorkflowPersistenceProvider

The persistence provider.

options PersistenceOptions

Options controlling stable keys for cross-process resume.

Methods

ExecuteAsync(IWorkflowOperation, IWorkflowFoundry, object?, Func<CancellationToken, Task<object?>>, CancellationToken)

Executes an operation within the persistence pipeline. Restores state when available, skips operations that were already completed, and checkpoints after successful execution. The current operation index is read from WorkflowForge.Constants.FoundryPropertyKeys.CurrentOperationIndex which the foundry sets before each middleware invocation.

public Task<object?> ExecuteAsync(IWorkflowOperation operation, IWorkflowFoundry foundry, object? inputData, Func<CancellationToken, Task<object?>> next, CancellationToken cancellationToken = default)

Parameters

operation IWorkflowOperation

The operation being executed.

foundry IWorkflowFoundry

The foundry execution context.

inputData object

The input data for the operation.

next Func<CancellationToken, Task<object>>

Delegate to invoke the next middleware/operation.

cancellationToken CancellationToken

A token to observe while waiting for the task to complete.

Returns

Task<object>

The operation result or the passthrough input when the step is skipped.