RuleWright 1.0.3
dotnet add package RuleWright --version 1.0.3
NuGet\Install-Package RuleWright -Version 1.0.3
<PackageReference Include="RuleWright" Version="1.0.3" />
<PackageVersion Include="RuleWright" Version="1.0.3" />
<PackageReference Include="RuleWright" />
paket add RuleWright --version 1.0.3
#r "nuget: RuleWright, 1.0.3"
#:package RuleWright@1.0.3
#addin nuget:?package=RuleWright&version=1.0.3
#tool nuget:?package=RuleWright&version=1.0.3
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. |
Documentation
| Get started | Install, your first rule, facts, error handling |
| Tutorials | A checkout pricing policy, fraud scoring, a rules web API, testing rule documents, the visual builder |
| Guides | Writing rules, extending the engine, running in production |
| API reference | Every public type and member |
Every code example in the documentation is compiled and run, and its output shown.
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.
Support and contact
Questions, feedback, support or licensing enquiries:
- ✉️ Email: salwan@albahadly.com
- 🌐 Website: www.albahadly.com
- 📖 Documentation: docs.albahadly.com/rulewright
License
MIT.
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- RuleWright.Core (>= 1.0.3)
- RuleWright.Execution (>= 1.0.3)
- RuleWright.Extensions.Functions (>= 1.0.3)
- RuleWright.Json.SystemText (>= 1.0.3)
- RuleWright.Serialization (>= 1.0.3)
-
.NETStandard 2.0
- RuleWright.Core (>= 1.0.3)
- RuleWright.Execution (>= 1.0.3)
- RuleWright.Extensions.Functions (>= 1.0.3)
- RuleWright.Json.SystemText (>= 1.0.3)
- RuleWright.Serialization (>= 1.0.3)
-
net10.0
- RuleWright.Core (>= 1.0.3)
- RuleWright.Execution (>= 1.0.3)
- RuleWright.Extensions.Functions (>= 1.0.3)
- RuleWright.Json.SystemText (>= 1.0.3)
- RuleWright.Serialization (>= 1.0.3)
-
net8.0
- RuleWright.Core (>= 1.0.3)
- RuleWright.Execution (>= 1.0.3)
- RuleWright.Extensions.Functions (>= 1.0.3)
- RuleWright.Json.SystemText (>= 1.0.3)
- RuleWright.Serialization (>= 1.0.3)
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.