← 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[]?, AssemblyReferenceProvider?)

Compiles all active rules from a single parameter. Uses an internal ExpressionCompiler.

// Compile: only the type matters, value can be null
var compileParam = new RuleParameter("customer", typeof(Customer));
workflow.Compile(compileParam);

// Execute: a real value is required
var executeParam = new RuleParameter("customer", typeof(Customer), customer);
var results = workflow.Execute(executeParam);

Execute(RuleParameter)

Sequential execution in priority order.

var results = workflow.Execute(parameter);

ExecuteParallel(RuleParameter)

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

var results = workflow.ExecuteParallel(parameter);

ExecuteAsync(RuleParameter, CancellationToken = default)

Async streaming with cancellation support.

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

ExecuteParallelAsync(RuleParameter, CancellationToken = default)

Parallel async execution.

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

ExecuteBufferedAsync(RuleParameter, int bufferSize = 10, CancellationToken = default)

Chunked streaming for large rule sets.

await foreach (var chunk in workflow.ExecuteBufferedAsync(parameter, 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.