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
providerIWorkflowPersistenceProviderThe persistence provider that saves, loads, and deletes workflow snapshots.
Exceptions
- ArgumentNullException
Thrown when
provideris null.
PersistenceMiddleware(IWorkflowPersistenceProvider, PersistenceOptions)
Initializes a new instance of the PersistenceMiddleware class with options for stable keys.
public PersistenceMiddleware(IWorkflowPersistenceProvider provider, PersistenceOptions options)
Parameters
providerIWorkflowPersistenceProviderThe persistence provider.
optionsPersistenceOptionsOptions 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
operationIWorkflowOperationThe operation being executed.
foundryIWorkflowFoundryThe foundry execution context.
inputDataobjectThe input data for the operation.
nextFunc<CancellationToken, Task<object>>Delegate to invoke the next middleware/operation.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.