← Back to API Reference

Workflow

Container for top-level rules. Owns compilation, validation, and execution orchestration.

public class Workflow : IRuleEngine

Properties

Property Type Description
Id Guid Unique identifier
Description string Human-readable purpose
IsActive bool When false, entire workflow is skipped
Rules IList<Rule> Top-level rules

Methods

Validate() / ValidateAll()

Validates all rules and checks workflow consistency.

workflow.Validate();     // Throws on errors
workflow.ValidateAll();  // Returns ValidationError[]

Compile(RuleParameter[], string[]?)

Compiles all active rules. Uses an internal ExpressionCompiler.

// Compile: only types matter, values can be null
var compileParams = new[] { new RuleParameter("customer", typeof(Customer)) };
workflow.Compile(compileParams);

// Execute: real values required
var executeParams = new[] { new RuleParameter("customer", typeof(Customer), customer) };
var results = workflow.Execute(executeParams);

Execute(params RuleParameter[])

Sequential execution in priority order.

var results = workflow.Execute(parameters);

ExecuteParallel(params RuleParameter[])

Parallel execution. Rules with dependencies execute after their dependencies complete.

var results = workflow.ExecuteParallel(parameters);

ExecuteAsync(params RuleParameter[], CancellationToken)

Async streaming with cancellation support.

await foreach (var result in workflow.ExecuteAsync(parameters, cts.Token))
{
    if (!result.Success) break; // Short-circuit
}

ExecuteParallelAsync(params RuleParameter[], CancellationToken)

Parallel async execution.

var results = await workflow.ExecuteParallelAsync(parameters, cts.Token);

ExecuteBufferedAsync(params RuleParameter[], int bufferSize, CancellationToken)

Chunked streaming for large rule sets.

await foreach (var chunk in workflow.ExecuteBufferedAsync(parameters, bufferSize: 10))
{
    ProcessBatch(chunk);
}

Execution Modes Comparison

Mode Use Case Overhead
Execute Default, predictable order Lowest
ExecuteParallel CPU-intensive rules, many independent rules Medium (thread scheduling)
ExecuteAsync Async I/O in rules, streaming results Low
ExecuteParallelAsync Async + parallel combined Highest
ExecuteBufferedAsync Large rule sets, chunked processing Low


Back to top

MIT License. Built with Roslyn + Typed Delegates.