VOOZH about

URL: https://www.nuget.org/packages/RulesEngine/

⇱ NuGet Gallery | RulesEngine 6.0.0




RulesEngine 6.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package RulesEngine --version 6.0.0
 
 
NuGet\Install-Package RulesEngine -Version 6.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="RulesEngine" Version="6.0.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RulesEngine" Version="6.0.0" />
 
Directory.Packages.props
<PackageReference Include="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 RulesEngine --version 6.0.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RulesEngine, 6.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 RulesEngine@6.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=RulesEngine&version=6.0.0
 
Install as a Cake Addin
#tool nuget:?package=RulesEngine&version=6.0.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Rules Engine

👁 build
👁 Coverage Status
👁 Nuget download

Overview

Rules Engine is a library/NuGet package for abstracting business logic/rules/policies out of a system. It provides a simple way of giving you the ability to put your rules in a store outside the core logic of the system, thus ensuring that any change in rules don't affect the core system.

Installation

To install this library, download the latest version of NuGet Package from nuget.org and refer it into your project.

How to use it

There are several ways to populate workflows for the Rules Engine as listed below.

You need to store the rules based on the schema definition given and they can be stored in any store as deemed appropriate like Azure Blob Storage, Cosmos DB, Azure App Configuration, Entity Framework, SQL Servers, file systems etc. For RuleExpressionType LambdaExpression, the rule is written as a lambda expressions.

An example rule:

[
 {
 "WorkflowName": "Discount",
 "Rules": [
 {
 "RuleName": "GiveDiscount10",
 "SuccessEvent": "10",
 "ErrorMessage": "One or more adjust rules failed.",
 "ErrorType": "Error",
 "RuleExpressionType": "LambdaExpression",
 "Expression": "input1.country == \"india\" AND input1.loyaltyFactor <= 2 AND input1.totalPurchasesToDate >= 5000"
 },
 {
 "RuleName": "GiveDiscount20",
 "SuccessEvent": "20",
 "ErrorMessage": "One or more adjust rules failed.",
 "ErrorType": "Error",
 "RuleExpressionType": "LambdaExpression",
 "Expression": "input1.country == \"india\" AND input1.loyaltyFactor >= 3 AND input1.totalPurchasesToDate >= 10000"
 }
 ]
 }
]

You can inject the rules into the Rules Engine by initiating an instance by using the following code -

var rulesEngine = new RulesEngine(workflow);

Here, workflow is a list of deserialized objects based on the schema explained above Once initialised, the Rules Engine needs to execute the rules for a given input. This can be done by calling the method ExecuteAllRulesAsync:

List<RuleResultTree> response = await rulesEngine.ExecuteAllRulesAsync(workflowName, input);

Here, workflowName is the name of the workflow, which is Discount in the above mentioned example. And input is the object which needs to be checked against the rules, which itself may consist of a list of class instances.

The response will contain a list of RuleResultTree which gives information if a particular rule passed or failed.

Note: A detailed example showcasing how to use Rules Engine is explained in Getting Started page of Rules Engine Wiki.

A demo app for the is available at this location.

Basic

A simple example via code only is as follows:

List<Rule> rules = new List<Rule>();

Rule rule = new Rule();
rule.RuleName = "Test Rule";
rule.SuccessEvent = "Count is within tolerance.";
rule.ErrorMessage = "Over expected.";
rule.Expression = "count < 3";
rule.RuleExpressionType = RuleExpressionType.LambdaExpression;
rules.Add(rule);

var workflows = new List<Workflow>();

Workflow exampleWorkflow = new Workflow();
exampleWorkflow.WorkflowName = "Example Workflow";
exampleWorkflow.Rules = rules;

workflows.Add(exampleWorkflow);

var bre = new RulesEngine.RulesEngine(workflows.ToArray());

Entity Framework

Consuming Entity Framework and populating the Rules Engine is shown in the EFDemo class with Workflow rules populating the array and passed to the Rules Engine, The Demo App includes an example RulesEngineDemoContext using SQLite and could be swapped out for another provider.

var wfr = db.Workflows.Include(i => i.Rules).ThenInclude(i => i.Rules).ToArray();
var bre = new RulesEngine.RulesEngine(wfr, null);

Note: For each level of nested rules expected, a ThenInclude query appended will be needed as shown above.

How it works

The rules can be stored in any store and be fed to the system in a structure which adheres to the schema of WorkFlow model.

A wrapper needs to be created over the Rules Engine package, which will get the rules and input message(s) from any store that your system dictates and put it into the Engine. The wrapper then handles the output using appropriate means.

Note: To know in detail of the workings of Rules Engine, please visit How it works section in Rules Engine Wiki.

3rd Party Tools

RulesEngine Editor

There is an editor library with it's own NuGet Package written in Blazor, more information is in it's repo https://github.com/alexreich/RulesEngineEditor.

Live Demo

https://alexreich.github.io/RulesEngineEditor

This can also be installed as a standalone PWA and used offline.

With Sample Data

https://alexreich.github.io/RulesEngineEditor/demo

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.


For more details please check out Rules Engine Wiki.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (31)

Showing the top 5 NuGet packages that depend on RulesEngine:

Package Downloads
EachShow.Host

主机启动程序

RulesEngineEditor

Editor for Microsoft RulesEngine - Blazor UI library intended for integration in Web or Desktop

ZhileTime.Hope.Points

Package Description

ZL.EdgeService

Package Description

Dignite.Abp.Points

Package Description

GitHub repositories (8)

Showing the top 8 popular GitHub repositories that depend on RulesEngine:

Repository Stars
microsurging/surging
Surging is a micro-service engine that provides a lightweight, high-performance, modular RPC request pipeline. support Event-based Asynchronous Pattern and reactive programming.
IoTSharp/IoTSharp
IoTSharp is an open-source IoT platform for data collection, processing, visualization, and device management.
colinin/abp-next-admin
这是基于vue-vben-admin 模板适用于abp vNext的前端管理项目
masastack/MASA.Framework
.NET next-generation microservice development framework, which provides cloud native best practices based on Dapr.
NimbleSense/Susalem
加入带锅宫酱,来到苏州耶路撒冷的怀抱吧!
alexreich/RulesEngineEditor
Editor for Microsoft RulesEngine - Blazor UI library intended for integration in Web or Desktop
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
zLulus/NotePractice
My_Note 笔记练习demo
Version Downloads Last Updated
6.0.1-preview.3 70 6/11/2026
6.0.1-preview.2 81 5/30/2026
6.0.1-preview.1 55 5/29/2026
6.0.0 1,433,467 6/4/2025
5.0.6 911,621 3/2/2025
5.0.5 479,633 1/30/2025
5.0.4 92,167 1/21/2025
5.0.3 3,405,901 1/12/2024
5.0.2 803,752 8/16/2023
5.0.1 274,100 7/12/2023
5.0.0 38,630 7/8/2023
4.0.0 1,940,005 10/2/2022
4.0.0-preview.1 12,221 4/25/2022
3.5.0 1,174,314 12/11/2021
3.4.0 108,185 10/1/2021
3.3.0 118,145 7/20/2021
3.2.0 125,029 6/8/2021
3.1.1 41,342 8/20/2021
3.1.0 78,270 4/28/2021
Loading failed