← Back to API Reference

IRuleEngine

Abstraction for dependency injection and unit testing.

public interface IRuleEngine

Methods

Method Returns Use Case
Compile(parameter, namespaces?) void One-time compilation
Execute(parameter) IEnumerable<RuleResult> Sequential execution
ExecuteAsync(parameter, ct) IAsyncEnumerable<RuleResult> Streaming async
ExecuteParallel(parameter) RuleResult[] CPU-bound parallel
ExecuteParallelAsync(parameter, ct) Task<RuleResult[]> Async parallel
Validate() void Pre-compile validation (throws)
ValidateAll() ValidationError[] Pre-compile validation (returns)

Every method takes a single RuleParameter. Wrap multiple values in a struct or class.


DI Registration

services.AddSingleton<IRuleEngine, Workflow>();
// Or
services.AddSingleton<IRuleEngine, RuleBatch>();

Mocking with Moq

var mock = new Mock<IRuleEngine>();
mock.Setup(x => x.Execute(It.IsAny<RuleParameter>()))
    .Returns(new[] { new RuleResult(true) });

var service = new MyService(mock.Object);

Implementations

Class When to Use
Workflow General-purpose rule container
RuleBatch 10+ rules with shared compilation context


Back to top

MIT License. Built with Roslyn + Typed Delegates.