Muonroi.RuleEngine.NRules 1.0.0-alpha.16

This is a prerelease version of Muonroi.RuleEngine.NRules.
dotnet add package Muonroi.RuleEngine.NRules --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.RuleEngine.NRules -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.NRules" 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.NRules" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.RuleEngine.NRules" />
                    
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.NRules --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.RuleEngine.NRules, 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.NRules@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.NRules&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.RuleEngine.NRules&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.RuleEngine.NRules

[FROZEN] NRules integration for the Muonroi rule-engine surface — no active development. Migrate to Muonroi.RuleEngine.Runtime.

NuGet License: Apache 2.0

This package wired the NRules forward-chaining rule engine into the Muonroi building-block ecosystem. It provides a singleton NRulesEngine that scans assemblies for NRules Rule subclasses, respects per-rule enable/version configuration via RuleOptions, and optionally exposes an HTTP management surface through NRulesController.

This package is frozen. All public types carry [Obsolete]. For new projects use Muonroi.RuleEngine.Runtime, which supersedes it with the full Abstractions v1.7+ Saga-pattern execution model.

Installation

dotnet add package Muonroi.RuleEngine.NRules --prerelease

Quick Start

The following is grounded in samples/Quickstart.RuleEngine.NRules/src/Quickstart.RuleEngine.NRules.Api/Program.cs.

1. Register the engine

// Program.cs
builder.Services.AddNRulesEngine(
    configure: options => builder.Configuration.GetSection("NRules").Bind(options),
    assemblies: typeof(Program).Assembly);   // scan this assembly for Rule subclasses

builder.Services.AddNRulesWeb();             // optional: registers NRulesController as an MVC part

// NRulesController requires IMDateTimeService from Muonroi.Core.
builder.Services.AddSingleton<IMDateTimeService, MDateTimeService>();

2. Define a rule

using NRules.Fluent.Dsl;
using Muonroi.RuleEngine.NRules;

[Rule("HighValueOrderDiscount", "1.0")]
public sealed class HighValueOrderDiscountRule : Rule
{
    public override void Define()
    {
        Order order = null!;

        When()
            .Match(() => order, o => o.Amount > 1000m);

        Then()
            .Do(_ => order.ApplyDiscount(0.10m));
    }
}

3. Fire rules

// Inject NRulesEngine and fire facts against it.
var order = new Order { Amount = 1500m };
nRulesEngine.Fire(order);

4. appsettings.json — enable/disable or pin a version

{
  "NRules": {
    "Rules": {
      "HighValueOrderDiscount": {
        "Enabled": true,
        "Version": "1.0"
      }
    }
  }
}

Features

  • Assembly scanning — locates every Rule subclass in the supplied assemblies at startup and compiles them into a reusable ISessionFactory.
  • Per-rule toggling — set Enabled: false in RuleOptions.Rules to exclude a rule without removing the class.
  • Version pinning — [Rule(name, version)] + RuleConfig.Version lets you deploy multiple versions of a rule and activate only the one you need.
  • Duplicate detection — throws MInternalException at startup if two enabled rules resolve to the same name, preventing silent conflicts.
  • HTTP surface — AddNRulesWeb() registers NRulesController (under api/v1/rule-engine/nrules) as an MVC application part for runtime inspection.
  • Manifest contributor — registers NRulesManifestContributor with the Muonroi UI-engine manifest pipeline.

Configuration

AddNRulesEngine accepts an Action<RuleOptions> configure callback and one or more Assembly arguments.

RuleOptions

Property Type Description
Rules Dictionary<string, RuleConfig> Per-rule configuration keyed by rule name (case-insensitive).

RuleConfig

Property Type Default Description
Enabled bool true Set to false to exclude this rule from the compiled session factory.
Version string? null If set, only the rule whose [Rule(..., version)] matches this value is compiled.

API Reference

Type Purpose
NRulesEngine Singleton rule executor. Scans assemblies, filters by RuleOptions, compiles via NRules RuleCompiler, and exposes Fire(params object[] facts).
RuleAttribute Class-level attribute [Rule(name, version)] that gives a rule a stable identity for RuleOptions configuration.
RuleOptions Options root bound from configuration; holds the Rules dictionary.
RuleConfig Per-rule settings: Enabled and Version.
ServiceCollectionExtensions AddNRulesEngine(configure, assemblies) — registers NRulesEngine as singleton. AddNRulesWeb() — adds NRulesController as MVC application part.

Samples

  • Quickstart.RuleEngine.NRules — demonstrates AddNRulesEngine + AddNRulesWeb with a HighValueOrderDiscountRule fact-matching order discounts.

Compatibility

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

License

Apache-2.0. See LICENSE-APACHE.

Deprecation notice: this package is frozen and receives no new features or bug fixes. Migrate to Muonroi.RuleEngine.Runtime.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 49 6/22/2026
Loading failed

v1.7.0: Updated to use new Abstractions v1.7.0 with Saga Pattern support. Compatible with ExecutionMode enum for flexible execution strategies.