Muonroi.RuleEngine.Core 1.0.0-alpha.16

This is a prerelease version of Muonroi.RuleEngine.Core.
dotnet add package Muonroi.RuleEngine.Core --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.RuleEngine.Core -Version 1.0.0-alpha.16
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Muonroi.RuleEngine.Core" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.RuleEngine.Core" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.RuleEngine.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Muonroi.RuleEngine.Core --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.RuleEngine.Core, 1.0.0-alpha.16"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Muonroi.RuleEngine.Core@1.0.0-alpha.16
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muonroi.RuleEngine.Core&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.RuleEngine.Core&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.RuleEngine.Core

Typed rule orchestration pipeline for .NET — register rules, hooks, and listeners, then execute them in dependency order against any context object.

NuGet License: Apache 2.0

Muonroi.RuleEngine.Core is the runtime implementation layer of the Muonroi rule engine stack. It provides RuleOrchestrator<TContext>, the fluent MRuleEngineBuilder<TContext>, execution-mode routing (RuleExecutionMode), workflow orchestration (MRuleWorkflowRunner), structured tracing, and audit hooks. It sits on top of Muonroi.RuleEngine.Abstractions (contracts) and integrates with Muonroi.Integration.Connectors for event bridge and webhook support.

Installation

dotnet add package Muonroi.RuleEngine.Core --prerelease

Quick Start

1. Register the engine (Program.cs)

using Muonroi.RuleEngine.Core;

builder.Services.AddRuleEngine<OrderRequest>();          // registers orchestrator + router
builder.Services.AddRulesFromAssemblies(typeof(Program).Assembly);  // scans IRule<T> and IHookHandler<T>

2. Implement a rule

using Muonroi.RuleEngine.Abstractions;

[RuleGroup("order-discount")]
public sealed class HighValueOrderRule : IRule<OrderRequest>
{
    public string Code => "HIGH_VALUE_ORDER";
    public int Order => 0;

    public Task<RuleResult> EvaluateAsync(OrderRequest context, FactBag facts, CancellationToken ct)
    {
        if (context.Amount <= 0)
            return Task.FromResult(RuleResult.Failure("Amount must be greater than zero."));

        bool isHighValue = context.Amount >= 1000m;
        facts.Set("discountRate", isHighValue ? 0.10m : 0m);
        facts.Set("isHighValueOrder", isHighValue);
        return Task.FromResult(RuleResult.Passed());
    }
}

3. Execute rules

public sealed class OrdersController(RuleOrchestrator<OrderRequest> orchestrator) : ControllerBase
{
    [HttpPost("evaluate")]
    public async Task<IActionResult> EvaluateAsync([FromBody] OrderRequest request, CancellationToken ct)
    {
        FactBag facts = await orchestrator.ExecuteAsync(request, cancellationToken: ct);
        decimal discountRate = facts.Get<decimal>("discountRate");
        return Ok(new { DiscountRate = discountRate });
    }
}

Features

  • Dependency-ordered execution — rules declare DependsOn (by code) and Dependencies (by type); the orchestrator topologically sorts them and detects cycles at startup.
  • Fluent builderAddRuleEngine<TContext>() returns MRuleEngineBuilder<TContext> with .AddRule<T>(), .AddHook<T>(), and .AddListener<T>() for inline registration without assembly scanning.
  • Assembly scanningAddRulesFromAssemblies(Assembly[]) registers all IRule<T> and IHookHandler<T> implementations, and maps [RuleGroup] / [TenantRuleGroup] keys to keyed DI entries.
  • Execution-mode routingIMRuleExecutionRouter<TContext> routes between Rules, Traditional, Parallel, and ABTest modes; weights and difference logging are controlled via MRuleEngineOptions.
  • Structured resultExecuteWithResultAsync(context, ExecutionMode, ...) returns OrchestratorResult with per-rule pass/fail, error list, and compensation errors.
  • Saga / compensation — rules that implement ICompensatableRule<TContext> are rolled back in reverse order when ExecutionMode.CompensateOnFailure is used.
  • Workflow orchestrationMRuleWorkflowRunner<TContext> drives step-by-step workflows (rule tasks, service tasks, gateways) defined via MRuleWorkflowDefinition<TContext>.
  • Tracing and auditIRuleExecutionTracer captures per-phase RuleTraceEntry records (BeforeEval, AfterEval, AfterExec, Error, Compensate); RuleAuditLogger and AuditTrailHook provide structured logging out of the box.
  • Tenant quota enforcement — when ITenantQuotaTracker is registered, the orchestrator enforces ConcurrentExecutions and RuleEvaluationsPerSecond quotas before each rule.
  • OpenTelemetry metricsRuleEngineTelemetry emits rules.matched, rules.fired, and rule.eval.duration_ms metrics with rule.id and rule.set.version tags.
  • Event bridge and webhooksAddRuleEventBridge() / AddRuleWebhook(WebhookOptions) wire IEventSink and IRuleWebhookNotifier for external event fan-out.

Configuration

builder.Services
    .AddRuleEngine<OrderRequest>(options =>
    {
        options.ExecutionMode = RuleExecutionMode.Rules;   // Rules | Traditional | Parallel | ABTest
        options.TraditionalWeight = 0.3;                   // only used in ABTest mode
        options.RulesWeight = 0.7;
        options.LogDifferences = true;                     // log fact diffs between modes
    })
    .AddRule<HighValueOrderRule>()
    .AddHook<MyAuditHook>()
    .AddListener<MyEventListener>();

// Optional: workflow execution safeguards
builder.Services.ConfigureRuleWorkflow(opts => opts.MaxSteps = 512);

MRuleEngineOptions is bound from services.Configure<MRuleEngineOptions>() and is also addressable via IOptions<MRuleEngineOptions> in any rule or hook.

API Reference

Type Purpose
RuleOrchestrator<TContext> Core pipeline — topologically sorts rules, runs hooks, traces, enforces quotas, emits OTel metrics. ExecuteAsync returns FactBag; ExecuteWithResultAsync returns OrchestratorResult.
MRuleEngineBuilder<TContext> Fluent builder returned by AddRuleEngine<TContext>(). Chain .AddRule<T>(), .AddHook<T>(), .AddListener<T>().
MRuleEngineOptions Runtime options: ExecutionMode, TraditionalWeight, RulesWeight, LogDifferences.
IMRuleExecutionRouter<TContext> Routes ExecuteAsync(context, traditionalPath?, modeOverride?) to the correct execution branch.
IMRuleWorkflowRunner<TContext> Executes an MRuleWorkflowDefinition<TContext> step-by-step, returning MRuleWorkflowResult<TContext>.
MRuleWorkflowDefinition<TContext> Declares workflow steps, start step, and transitions.
MRuleWorkflowStep<TContext> A single step (rule task, service task, or gateway) within a workflow.
MRuleWorkflowOptions MaxSteps (default 256) — guards against cyclic workflow transitions.
IRuleExecutionTracer Receives RuleTraceEntry records per rule phase. Implement to persist traces to any store.
IRuleTraceStore Persistence contract consumed by tracer implementations.
IRuleDebuggerModeService Enables/disables per-tenant debug tracing at runtime.
ITraceRedactor Redacts sensitive fact values before traces are written.
RuleAuditLogger<TContext> Built-in IRuleEventListener<TContext> that logs matched and fired events via IMLog.
AuditTrailHook<TContext> Built-in IHookHandler<TContext> that writes audit trail entries at BeforeRule / AfterRule hook points.
IEventSink Receives domain events emitted by the rule pipeline; registered via AddRuleEventBridge().
IRuleWebhookNotifier Delivers rule events to configured HTTP webhook endpoints.
IFeatureFlagClient Contract for feature-flag evaluation integrated into rule conditions.
FeatureFlagEvaluator Default implementation of IFeatureFlagClient.

Samples

  • Quickstart.RuleEngine — minimal ASP.NET Core API: AddRuleEngine<OrderRequest>(), AddRulesFromAssemblies, and RuleOrchestrator<T> injection in a controller.

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS)

License

Apache-2.0. See LICENSE-APACHE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Muonroi.RuleEngine.Core:

Package Downloads
Muonroi.Tenancy.SiteProfile.Web

ASP.NET Core middleware and SignalR hot-reload for Muonroi.Tenancy.SiteProfile.

Muonroi.RuleEngine.Testing

Testing helpers for Muonroi rule orchestration.

Muonroi.RuleEngine.Runtime

Runtime orchestration layer for Muonroi RuleEngine, providing execution pipelines and integration points for rule evaluation services.

Muonroi.BuildingBlock.All

Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup.

Muonroi.AspNetCore.RuleEngine

ASP.NET Core rule engine integration: Auto CRUD with RuleOrchestrator, generic controllers, and rule change management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 75 6/22/2026
1.0.0-alpha.15 137 5/31/2026
1.0.0-alpha.14 146 5/15/2026
1.0.0-alpha.13 124 5/2/2026
1.0.0-alpha.12 89 4/2/2026
1.0.0-alpha.11 136 4/2/2026
1.0.0-alpha.9 68 3/30/2026
1.0.0-alpha.8 179 3/28/2026
1.0.0-alpha.7 64 3/27/2026
1.0.0-alpha.5 65 3/27/2026
1.0.0-alpha.4 75 3/27/2026
1.0.0-alpha.3 63 3/27/2026
1.0.0-alpha.2 71 3/26/2026
1.0.0-alpha.1 87 3/8/2026
Loading failed

v1.7.0: Updated to use new Abstractions v1.7.0 with Saga Pattern support. Added 48 new Theory tests for comprehensive edge case coverage.