Table of Contents

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

TInput

The input data type.

TOutput

The 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

name string

The name of the operation.

executeFunc Func<TInput, IWorkflowFoundry, CancellationToken, Task<TOutput>>

The strongly-typed function to execute.

restoreFunc Func<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

string

Methods

ForgeAsyncCore(TInput, IWorkflowFoundry, CancellationToken)

Executes the strongly-typed operation logic.

protected override Task<TOutput> ForgeAsyncCore(TInput inputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)

Parameters

inputData TInput

The typed input data.

foundry IWorkflowFoundry

The workflow foundry providing context and services.

cancellationToken CancellationToken

The 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

name string

The operation name.

func Func<TInput, Task<TOutput>>

The asynchronous function to execute.

restoreFunc Func<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

name string

The operation name.

func Func<TInput, TOutput>

The synchronous function to execute.

restoreFunc Func<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

outputData TOutput

The typed output data to restore.

foundry IWorkflowFoundry

The workflow foundry providing context and services.

cancellationToken CancellationToken

The 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

name string

The operation name.

func Func<TInput, IWorkflowFoundry, Task<TOutput>>

The function with foundry access.

restoreFunc Func<TOutput, IWorkflowFoundry, CancellationToken, Task>

Optional restoration function for compensation.

Returns

DelegateWorkflowOperation<TInput, TOutput>

A new strongly-typed delegate workflow operation.