RulesEngine documentation
RulesEngine is a highly extensible .NET library for building rule-based systems from C# expressions. You keep business rules, policies and validations outside your code (in JSON, a database or any store you choose), and change them without redeploying.
Features
- JSON-based rule definitions that map onto plain classes.
- Several inputs per call, including typed objects, anonymous types,
ExpandoObjectand dictionaries. - C# expressions with LINQ, extensible with your own types.
- Global and local parameters for readable rules, and nested
And/Orrules. - Actions after evaluation, including chaining rules, and custom actions.
- A standalone expression evaluator.
- Targets .NET 6, 8, 9, 10 and .NET Standard 2.0 and 2.1.
Install
dotnet add package RulesEngine
Find what you need
| I want to... | Go to |
|---|---|
| Learn the library by building something | Your first workflow, then Nested rules and scoped parameters |
| Solve a specific problem | Load rules · Custom types and actions · Performance · Troubleshooting · Upgrade |
| Look up exact details | Workflow JSON · ReSettings · Expression language · Error handling · API overview |
| Understand how it works | Architecture · Evaluation pipeline · Caching · Input typing · Type security · Actions |
| See why it was designed this way | Architecture decision records |
| Improve these docs | Contributing to the documentation |
| Find a section of the old documentation | Moved content |
Quick look
[
{
"WorkflowName": "Discount",
"Rules": [
{
"RuleName": "GiveDiscount10",
"SuccessEvent": "10",
"Expression": "input1.country == \"india\" AND input1.loyaltyFactor <= 2 AND input1.totalPurchasesToDate >= 5000"
}
]
}
]
var engine = new RulesEngine.RulesEngine(workflows);
List<RuleResultTree> results = await engine.ExecuteAllRulesAsync("Discount", customer);
results.OnSuccess(eventName => Console.WriteLine($"Discount: {eventName}%"));
Project
- Source, issues and discussions: https://github.com/microsoft/RulesEngine
- NuGet package: https://www.nuget.org/packages/RulesEngine/
- Change log
- Maintained by Purunjay Bhal and Yogesh Prajapati. See MAINTAINERS.md and CONTRIBUTING.md.
- Licensed under the MIT License.