Class WorkflowBuilder
- Namespace
- WorkflowForge
- Assembly
- WorkflowForge.dll
Fluent builder for constructing workflow definitions. Provides a clean API for configuring workflow properties and operations.
public sealed class WorkflowBuilder
- Inheritance
-
WorkflowBuilder
- Inherited Members
Methods
AddOperation(string, Action<IWorkflowFoundry>, Action<IWorkflowFoundry>?)
Adds an inline synchronous operation to the workflow. This provides a quick way to add simple operations without creating separate classes. Note: Synchronous operations will be wrapped to run asynchronously.
public WorkflowBuilder AddOperation(string name, Action<IWorkflowFoundry> action, Action<IWorkflowFoundry>? restoreAction = null)
Parameters
namestringThe name of the operation for identification purposes.
actionAction<IWorkflowFoundry>The synchronous action to execute. Receives the workflow foundry.
restoreActionAction<IWorkflowFoundry>Optional synchronous restoration action for compensation.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentException
Thrown when name is null, empty, or whitespace.
- ArgumentNullException
Thrown when action is null.
AddOperation(string, Func<IWorkflowFoundry, CancellationToken, Task>, Func<IWorkflowFoundry, CancellationToken, Task>?)
Adds an inline asynchronous operation to the workflow. This provides a quick way to add simple operations without creating separate classes.
public WorkflowBuilder AddOperation(string name, Func<IWorkflowFoundry, CancellationToken, Task> action, Func<IWorkflowFoundry, CancellationToken, Task>? restoreAction = null)
Parameters
namestringThe name of the operation for identification purposes.
actionFunc<IWorkflowFoundry, CancellationToken, Task>The asynchronous action to execute. Receives the workflow foundry and cancellation token.
restoreActionFunc<IWorkflowFoundry, CancellationToken, Task>Optional asynchronous restoration action for compensation.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentException
Thrown when name is null, empty, or whitespace.
- ArgumentNullException
Thrown when action is null.
AddOperation(IWorkflowOperation)
Adds a workflow operation to the execution sequence. Operations are executed in the order they are added.
public WorkflowBuilder AddOperation(IWorkflowOperation operation)
Parameters
operationIWorkflowOperationThe operation to add. Cannot be null.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown when operation is null.
AddOperation<T>()
Adds a workflow operation by type using dependency injection. The operation will be resolved from the service provider when the workflow executes.
public WorkflowBuilder AddOperation<T>() where T : class, IWorkflowOperation
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Type Parameters
TThe type of operation to add. Must implement IWorkflowOperation.
Exceptions
- InvalidOperationException
Thrown when no service provider is available.
AddOperations(IEnumerable<IWorkflowOperation>)
Adds multiple workflow operations to the execution sequence. Operations are executed in the order they are provided.
public WorkflowBuilder AddOperations(IEnumerable<IWorkflowOperation> operations)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to add. Cannot be null.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown when operations is null.
AddOperations(params IWorkflowOperation[])
Adds multiple workflow operations to the execution sequence. Operations are executed in the order they are provided.
public WorkflowBuilder AddOperations(params IWorkflowOperation[] operations)
Parameters
operationsIWorkflowOperation[]The operations to add. Cannot be null.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown when operations is null.
AddParallelOperations(IEnumerable<IWorkflowOperation>, int?, TimeSpan?, string?)
Adds multiple operations to be executed in parallel with configurable concurrency. All operations receive the same input data (shared input strategy).
public WorkflowBuilder AddParallelOperations(IEnumerable<IWorkflowOperation> operations, int? maxConcurrency = null, TimeSpan? timeout = null, string? name = null)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to execute in parallel. Cannot be null or empty.
maxConcurrencyint?Optional maximum number of concurrent operations.
timeoutTimeSpan?Optional timeout for the entire parallel execution.
namestringOptional name for the parallel operation group.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown when operations is null.
- ArgumentException
Thrown when operations is empty.
AddParallelOperations(params IWorkflowOperation[])
Adds multiple operations to be executed in parallel. All operations receive the same input data (shared input strategy).
public WorkflowBuilder AddParallelOperations(params IWorkflowOperation[] operations)
Parameters
operationsIWorkflowOperation[]The operations to execute in parallel. Cannot be null or empty.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentNullException
Thrown when operations is null.
- ArgumentException
Thrown when operations is empty.
Build()
Builds the configured workflow.
public IWorkflow Build()
Returns
- IWorkflow
A workflow instance ready for execution.
Exceptions
- InvalidOperationException
Thrown when the workflow configuration is invalid.
Parallel(params IWorkflowOperation[])
Creates a parallel workflow from the specified operations.
public static IWorkflow Parallel(params IWorkflowOperation[] operations)
Parameters
operationsIWorkflowOperation[]The operations to execute in parallel.
Returns
- IWorkflow
A workflow that executes operations in parallel.
Exceptions
- ArgumentNullException
Thrown when operations is null.
- ArgumentException
Thrown when operations is empty.
Sequential(params IWorkflowOperation[])
Creates a sequential workflow from the specified operations.
public static IWorkflow Sequential(params IWorkflowOperation[] operations)
Parameters
operationsIWorkflowOperation[]The operations to execute sequentially.
Returns
- IWorkflow
A workflow that executes operations in sequence.
Exceptions
- ArgumentNullException
Thrown when operations is null.
- ArgumentException
Thrown when operations is empty.
WithDescription(string?)
Sets an optional description for the workflow. This provides additional context about the workflow's purpose.
public WorkflowBuilder WithDescription(string? description)
Parameters
descriptionstringThe workflow description. Can be null.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
WithName(string)
Sets the name of the workflow. This is a human-readable identifier for the workflow instance.
public WorkflowBuilder WithName(string name)
Parameters
namestringThe workflow name. Cannot be null, empty, or whitespace.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentException
Thrown when name is null, empty, or whitespace.
WithVersion(string)
Sets the version of the workflow. This helps with workflow versioning and change management.
public WorkflowBuilder WithVersion(string version)
Parameters
versionstringThe workflow version. Cannot be null, empty, or whitespace.
Returns
- WorkflowBuilder
The current WorkflowBuilder instance for method chaining.
Exceptions
- ArgumentException
Thrown when version is null, empty, or whitespace.