Class DelegateWorkflowOperation<TInput, TOutput>
- Namespace
- WorkflowForge.Operations
- Assembly
- WorkflowForge.dll
A strongly-typed workflow operation that wraps a delegate function. Use this for simple, ad-hoc typed operations. For complex business logic, consider creating a dedicated class that inherits from WorkflowOperationBase<TInput, TOutput>.
public sealed class DelegateWorkflowOperation<TInput, TOutput> : WorkflowOperationBase<TInput, TOutput>, IWorkflowOperation<TInput, TOutput>, IWorkflowOperation, IDisposable
Type Parameters
TInputThe input data type.
TOutputThe output data type.
- Inheritance
-
WorkflowOperationBase<TInput, TOutput>DelegateWorkflowOperation<TInput, TOutput>
- Implements
-
IWorkflowOperation<TInput, TOutput>
- Inherited Members
- Extension Methods
Constructors
DelegateWorkflowOperation(string, Func<TInput, IWorkflowFoundry, CancellationToken, Task<TOutput>>, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>?)
Initializes a new instance of the DelegateWorkflowOperation<TInput, TOutput> class.
public DelegateWorkflowOperation(string name, Func<TInput, IWorkflowFoundry, CancellationToken, Task<TOutput>> executeFunc, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe name of the operation.
executeFuncFunc<TInput, IWorkflowFoundry, CancellationToken, Task<TOutput>>The strongly-typed function to execute.
restoreFuncFunc<TOutput, IWorkflowFoundry, CancellationToken, Task>The optional strongly-typed restoration function.
Properties
Name
Gets the name of this operation.
public override string Name { get; }
Property Value
Methods
ForgeAsyncCore(TInput, IWorkflowFoundry, CancellationToken)
Executes the strongly-typed operation logic.
protected override Task<TOutput> ForgeAsyncCore(TInput inputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
inputDataTInputThe typed input data.
foundryIWorkflowFoundryThe workflow foundry providing context and services.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TOutput>
The typed output data.
FromAsync(string, Func<TInput, Task<TOutput>>, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>?)
Creates a strongly-typed operation from an asynchronous function.
public static DelegateWorkflowOperation<TInput, TOutput> FromAsync(string name, Func<TInput, Task<TOutput>> func, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
funcFunc<TInput, Task<TOutput>>The asynchronous function to execute.
restoreFuncFunc<TOutput, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation<TInput, TOutput>
A new strongly-typed delegate workflow operation.
FromSync(string, Func<TInput, TOutput>, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>?)
Creates a strongly-typed operation from a synchronous function.
public static DelegateWorkflowOperation<TInput, TOutput> FromSync(string name, Func<TInput, TOutput> func, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
funcFunc<TInput, TOutput>The synchronous function to execute.
restoreFuncFunc<TOutput, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation<TInput, TOutput>
A new strongly-typed delegate workflow operation.
RestoreAsync(TOutput, IWorkflowFoundry, CancellationToken)
Restores the strongly-typed operation effects if supported.
public override Task RestoreAsync(TOutput outputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
outputDataTOutputThe typed output data to restore.
foundryIWorkflowFoundryThe workflow foundry providing context and services.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task
A task representing the restoration operation.
WithFoundry(string, Func<TInput, IWorkflowFoundry, Task<TOutput>>, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>?)
Creates a strongly-typed operation with access to the workflow foundry.
public static DelegateWorkflowOperation<TInput, TOutput> WithFoundry(string name, Func<TInput, IWorkflowFoundry, Task<TOutput>> func, Func<TOutput, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
funcFunc<TInput, IWorkflowFoundry, Task<TOutput>>The function with foundry access.
restoreFuncFunc<TOutput, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation<TInput, TOutput>
A new strongly-typed delegate workflow operation.