Rulewright 0.3.0
dotnet add package Rulewright --version 0.3.0
NuGet\Install-Package Rulewright -Version 0.3.0
<PackageReference Include="Rulewright" Version="0.3.0" />
<PackageVersion Include="Rulewright" Version="0.3.0" />
<PackageReference Include="Rulewright" />
paket add Rulewright --version 0.3.0
#r "nuget: Rulewright, 0.3.0"
#:package Rulewright@0.3.0
#addin nuget:?package=Rulewright&version=0.3.0
#tool nuget:?package=Rulewright&version=0.3.0
Rulewright
A high-performance, JSON-driven business rule engine for .NET. Rules are plain JSON documents; evaluation is compiled expression trees — parse once, compile once, execute millions of times.
This is the main package: install it and you have the whole engine.
Install
dotnet add package Rulewright
That covers everything on this page — the domain model, the JSON parser and schema
validator, the evaluation engine, the System.Text.Json adapter, and the built-in custom
functions all come with it.
A rule
{
"id": "discount-rule-01",
"description": "VIP or high-value customers get 10% off",
"priority": 10,
"condition": {
"type": "group",
"operator": "AND",
"rules": [
{ "field": "Customer.Age", "operator": "GreaterThan", "value": 18 },
{
"type": "group",
"operator": "OR",
"rules": [
{ "field": "Order.Total", "operator": "GreaterThanOrEqual", "value": 100 },
{ "field": "Customer.IsVip", "operator": "Equals", "value": true }
]
}
]
},
"actions": [
{ "type": "setOutput", "target": "Discount", "value": 10 }
]
}
Evaluate it
using Rulewright.Core;
using Rulewright.Execution;
using Rulewright.Json.SystemText;
var engine = new RulewrightBuilder()
.UseJsonReader(new SystemTextJsonReader())
.Build();
LoadedRuleSet ruleSet = engine.LoadRuleSet(json); // parse + validate once
RuleEvaluationResult result = engine.Evaluate(ruleSet, customerOrder, new EvaluationOptions
{
EnableTrace = true,
});
foreach (FiredRule fired in result.FiredRules)
Console.WriteLine($"{fired.RuleId} -> {string.Join(", ", fired.Outputs)}");
Facts can be typed POCOs (compiled path — expression-tree delegates, no reflection at
evaluation time) or IDictionary<string, object> (interpreted path). The result reports
which path ran via CompilationMode, so a fallback is never silent.
What you get
- Compiled, not interpreted. Rules compile to delegates and are cached by a content hash of the rule, not its id — editing a rule's body invalidates the cache, reformatting it does not.
- A closed, validatable operator vocabulary. No embedded code or expression strings in
rule files: comparison, string (ordinal), collection, and null operators,
AND/OR/NOTgroups, plus an extensiblecustomoperator bound to functions you register. - Computed values and accumulators. Action values can be arithmetic/
concat/coalesceexpressions over fact fields;addToOutputandappendToOutputaccumulate across fired rules,removeOutputretracts, andelsebranches run when a condition fails. - Decision tables.
decisionTabledocuments expand into ordinary rules withhitPolicy: "first"or"collect". - Opt-in execution traces recording which rules fired and which condition nodes passed, failed, or were short-circuited — with zero overhead when disabled (a separate compiled fast path, not a runtime flag check).
- Structured validation.
RuleSetValidatorreturns JSON-pointer-addressed errors, andRuleSchemaCatalogenumerates the whole authoring vocabulary at runtime for a builder UI.
Picking pieces instead
| Package | When |
|---|---|
Rulewright.Execution |
The engine, without a JSON adapter or the built-in functions. |
Rulewright.Json.NewtonsoftJson |
Use Newtonsoft.Json instead of System.Text.Json. |
Rulewright.Serialization |
Validate or hash rule documents without evaluating them. |
Rulewright.Core |
Reference the domain model alone. Zero dependencies. |
Requirements
.NET Framework 4.8, .NET Standard 2.0, .NET 8.0 or .NET 10.0.
NativeAOT: the compiled path uses Expression.Compile, which NativeAOT does not support.
Use dictionary facts there — the engine reports CompilationMode.Interpreted.
License
MIT.
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- Rulewright.Core (>= 0.3.0)
- Rulewright.Execution (>= 0.3.0)
- Rulewright.Extensions.Functions (>= 0.3.0)
- Rulewright.Json.SystemText (>= 0.3.0)
- Rulewright.Serialization (>= 0.3.0)
-
.NETStandard 2.0
- Rulewright.Core (>= 0.3.0)
- Rulewright.Execution (>= 0.3.0)
- Rulewright.Extensions.Functions (>= 0.3.0)
- Rulewright.Json.SystemText (>= 0.3.0)
- Rulewright.Serialization (>= 0.3.0)
-
net10.0
- Rulewright.Core (>= 0.3.0)
- Rulewright.Execution (>= 0.3.0)
- Rulewright.Extensions.Functions (>= 0.3.0)
- Rulewright.Json.SystemText (>= 0.3.0)
- Rulewright.Serialization (>= 0.3.0)
-
net8.0
- Rulewright.Core (>= 0.3.0)
- Rulewright.Execution (>= 0.3.0)
- Rulewright.Extensions.Functions (>= 0.3.0)
- Rulewright.Json.SystemText (>= 0.3.0)
- Rulewright.Serialization (>= 0.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See https://github.com/albahadly/rulewright/releases for release notes.