RulesEngineEx 6.0.1
See the version list below for details.
dotnet add package RulesEngineEx --version 6.0.1
NuGet\Install-Package RulesEngineEx -Version 6.0.1
<PackageReference Include="RulesEngineEx" Version="6.0.1" />
paket add RulesEngineEx --version 6.0.1
#r "nuget: RulesEngineEx, 6.0.1"
// Install RulesEngineEx as a Cake Addin #addin nuget:?package=RulesEngineEx&version=6.0.1 // Install RulesEngineEx as a Cake Tool #tool nuget:?package=RulesEngineEx&version=6.0.1
Rules Engine
Overview
forked from which does not appear to be maintained anymore
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.
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.asulwer.com.
For more details please check out Rules Engine Wiki.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- FastExpressionCompiler (>= 4.2.1)
- FluentValidation (>= 11.9.2)
- Microsoft.CSharp (>= 4.7.0)
- System.Linq.Dynamic.Core (>= 1.4.3)
- System.Text.Json (>= 8.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.