ND.FW.RulesEngine 1.0.0

dotnet add package ND.FW.RulesEngine --version 1.0.0
                    
NuGet\Install-Package ND.FW.RulesEngine -Version 1.0.0
                    
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="ND.FW.RulesEngine" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ND.FW.RulesEngine" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ND.FW.RulesEngine" />
                    
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 ND.FW.RulesEngine --version 1.0.0
                    
#r "nuget: ND.FW.RulesEngine, 1.0.0"
                    
#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 ND.FW.RulesEngine@1.0.0
                    
#: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=ND.FW.RulesEngine&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ND.FW.RulesEngine&version=1.0.0
                    
Install as a Cake Tool

NdRulesEngine

A minimal, JSON-configurable rule engine built on top of Microsoft RulesEngine. Rules are pure config — no C# changes needed to add or change a rule.

Install

dotnet add package NdRulesEngine

Concepts

Concept Purpose
Workflow A named group of rules, loaded from JSON
Rule A single condition (Expression) evaluated against the input
Plugin Fetches/enriches context data before rules run (no validation logic)
Custom Operator A static C# method callable directly from an Expression

Quick Start

var services = new ServiceCollection();
services.AddNdRulesEngine();
var provider = services.BuildServiceProvider();

var registry = provider.GetRequiredService<INdPluginRegistry>();
registry.ScanAssembly(typeof(Program).Assembly); // discovers [NdPlugin] classes

var engine = provider.GetRequiredService<INdRuleEngine>();
engine.LoadWorkflowFromJson(File.ReadAllText("rules.json"));

var input = new Dictionary<string, object?> { ["phone"] = "+919876543210", ["age"] = 10 };
var results = await engine.ExecuteAsync("CustomerValidation", input);

foreach (var r in results)
    Console.WriteLine($"{r.RuleName}: {(r.IsSuccess ? "PASS" : $"FAIL - {r.ErrorMessage}")}");

Rule JSON

{
  "WorkflowName": "CustomerValidation",
  "Rules": [
    {
      "RuleName": "PhoneRequired",
      "Expression": "input1[\"phone\"] != null && input1[\"phone\"].ToString() != \"\"",
      "ErrorMessage": "Phone is required."
    }
  ]
}
  • Use bracket notationinput1["field"] — not dot notation. RulesEngine compiles expressions statically and can't resolve dynamic dot-access at runtime.
  • Set "Enabled": false to disable a rule without deleting it.

Plugins (context enrichment)

Plugins run before evaluation to fetch or derive values — not to validate.

[NdPlugin("AgeLookupPlugin")]
public sealed class AgeLookupPlugin : INdContextPlugin
{
    public Task EnrichAsync(IDictionary<string, object?> context, IDictionary<string, object?>? parameters, CancellationToken ct = default)
    {
        context["age"] = 25; // e.g. fetched from an external API
        return Task.CompletedTask;
    }
}

Attach it to a rule in JSON:

{
  "RuleName": "AgeMinimum",
  "Expression": "Convert.ToInt32(input1[\"age\"]) >= 18",
  "ErrorMessage": "Age must be 18 or above.",
  "Plugins": [{ "Name": "AgeLookupPlugin" }]
}

A rule can list multiple plugins; they run in order before the workflow evaluates.

Custom Operators

Any static class can be registered and called by name inside expressions.

public static class Operators
{
    public static bool IsValidPan(object? value) =>
        System.Text.RegularExpressions.Regex.IsMatch(value?.ToString() ?? "", "^[A-Z]{5}[0-9]{4}[A-Z]$");
}

services.AddNdRulesEngine(o => o.CustomOperatorTypes.Add(typeof(Operators)));
{ "RuleName": "PanFormat", "Expression": "Operators.IsValidPan(input1[\"pan\"])", "ErrorMessage": "Invalid PAN." }

Custom operator methods must take object? parameters — RulesEngine passes ExpandoObject values as object?.

API Surface

  • INdRuleEngine.LoadWorkflow(NdWorkflowDefinition) / .LoadWorkflowFromJson(string)
  • INdRuleEngine.ExecuteAsync(workflowName, input)IReadOnlyList<NdRuleResult>
  • INdPluginRegistry.Register(name, plugin) / .ScanAssembly(assembly)
  • NdRuleEngineOptions.CustomOperatorTypes — list of static classes to expose to expressions

License

Internal use.

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 118 7/2/2026