This article is a mirror article of machine translation, please click here to jump to the original article.

View: 54363|Reply: 1

[Source] .NET/C# Rule Engine RulesEngine tutorial

[Copy link]
Posted on 3/29/2021 1:56:10 PM | | | |
RulesEngine is a library/NuGet package used to abstract business logic/rules/policies from the system. This can work in a very simple way by enabling you to place rules in storage outside of the core logic of the system, ensuring that any changes to the rules do not affect the core system.

Applicable scenarios:

  • The number of input and output types is relatively fixed, but the execution logic changes frequently.
  • switch conditions change frequently, and complex switch statements are replaced;
  • business logic with multiple conditions or rules that will change;
  • Scenarios where the rule freedom does not require particularly high degrees of freedom. (In this case, a scripting engine is recommended)


The rules of RulesEngine are stored in JSON, and the rules (Rules) are expressed in lambda expressions.

GitHub address:The hyperlink login is visible.

Document address:The hyperlink login is visible.(I personally feel that the documentation is a bit vague, and some usage is not explained too clearly)

First, create a new .NET Core 3.1 console project and use the nuget command to install the package, as follows:

Create a new rule file :Rules.json set to copy to the output directory.

The configuration is as follows:

Try running the program and the output is as follows:



The customTest workflow will call our C# function to validate the rules, note that when instantiating the RulesEngine object, we need to add ReSettings to execute our C# method normally.

Among them,Validation sets are more abstract to understand, will use localParams, the keyword of the local variable is localParams, which can be simply understood as var name = expression

The full code is as follows:

Source code download:

Tourists, if you want to see the hidden content of this post, pleaseReply






Previous:.NET Core watermarking issues on Linux pictures
Next:.NET sets the default SDK version
 Landlord| Posted on 8/30/2023 6:51:41 PM |
Rule Engine Editor:The hyperlink login is visible.
Rule Engine Editor Online Demo:The hyperlink login is visible.

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com