Muonroi.RuleEngine.Core
1.0.0-alpha.16
dotnet add package Muonroi.RuleEngine.Core --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.RuleEngine.Core -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.RuleEngine.Core" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.RuleEngine.Core" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.RuleEngine.Core" />
paket add Muonroi.RuleEngine.Core --version 1.0.0-alpha.16
#r "nuget: Muonroi.RuleEngine.Core, 1.0.0-alpha.16"
#:package Muonroi.RuleEngine.Core@1.0.0-alpha.16
#addin nuget:?package=Muonroi.RuleEngine.Core&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.RuleEngine.Core&version=1.0.0-alpha.16&prerelease
Muonroi.RuleEngine.Core
Typed rule orchestration pipeline for .NET — register rules, hooks, and listeners, then execute them in dependency order against any context object.
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) andDependencies(by type); the orchestrator topologically sorts them and detects cycles at startup. - Fluent builder —
AddRuleEngine<TContext>()returnsMRuleEngineBuilder<TContext>with.AddRule<T>(),.AddHook<T>(), and.AddListener<T>()for inline registration without assembly scanning. - Assembly scanning —
AddRulesFromAssemblies(Assembly[])registers allIRule<T>andIHookHandler<T>implementations, and maps[RuleGroup]/[TenantRuleGroup]keys to keyed DI entries. - Execution-mode routing —
IMRuleExecutionRouter<TContext>routes betweenRules,Traditional,Parallel, andABTestmodes; weights and difference logging are controlled viaMRuleEngineOptions. - Structured result —
ExecuteWithResultAsync(context, ExecutionMode, ...)returnsOrchestratorResultwith per-rule pass/fail, error list, and compensation errors. - Saga / compensation — rules that implement
ICompensatableRule<TContext>are rolled back in reverse order whenExecutionMode.CompensateOnFailureis used. - Workflow orchestration —
MRuleWorkflowRunner<TContext>drives step-by-step workflows (rule tasks, service tasks, gateways) defined viaMRuleWorkflowDefinition<TContext>. - Tracing and audit —
IRuleExecutionTracercaptures per-phaseRuleTraceEntryrecords (BeforeEval, AfterEval, AfterExec, Error, Compensate);RuleAuditLoggerandAuditTrailHookprovide structured logging out of the box. - Tenant quota enforcement — when
ITenantQuotaTrackeris registered, the orchestrator enforcesConcurrentExecutionsandRuleEvaluationsPerSecondquotas before each rule. - OpenTelemetry metrics —
RuleEngineTelemetryemitsrules.matched,rules.fired, andrule.eval.duration_msmetrics withrule.idandrule.set.versiontags. - Event bridge and webhooks —
AddRuleEventBridge()/AddRuleWebhook(WebhookOptions)wireIEventSinkandIRuleWebhookNotifierfor 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, andRuleOrchestrator<T>injection in a controller.
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.RuleEngine.Abstractions— contracts (IRule<T>,IHookHandler<T>,IRuleEventListener<T>,FactBag,RuleResult); required by all rule implementations.Muonroi.RuleEngine.Runtime— file-backedIRuleSetStore,RulesEngineService, and hot-reload support.Muonroi.RuleEngine.EntityFrameworkCore— Postgres-backed rule store viaAddMRuleEngineWithPostgres().Muonroi.RuleEngine.SourceGenerators— compile-time dispatcher generation for rule contexts.Muonroi.RuleEngine.Testing— test harness and assertion helpers for rules.
License
Apache-2.0. See LICENSE-APACHE.
| Product | Versions 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. |
-
net8.0
- MailKit (>= 4.17.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Http (>= 10.0.3)
- Microsoft.Extensions.Logging (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Governance.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Integration.Connectors (>= 1.0.0-alpha.16)
- Muonroi.Logging.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.RuleEngine.Abstractions (>= 1.0.0-alpha.16)
- Scrutor (>= 4.1.0)
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 |
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.