https://github.com/ayayalar/DotNetRuleEngine
.net standard v2
https://github.com/ayayalar/DotNetRuleEngine
rule rule-engine rules rules-engine rules-processor
Last synced: 10 months ago
JSON representation
.net standard v2
- Host: GitHub
- URL: https://github.com/ayayalar/DotNetRuleEngine
- Owner: ayayalar
- Created: 2017-04-12T21:34:20.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-12-31T23:51:12.000Z (about 6 years ago)
- Last Synced: 2025-03-24T06:53:15.932Z (11 months ago)
- Topics: rule, rule-engine, rules, rules-engine, rules-processor
- Language: C#
- Homepage:
- Size: 44.9 KB
- Stars: 35
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
> DotNetRuleEngine allows you to write your code as series of rules to keep your code clean and structured. Supports both **synchronous** and **asynchronous** patterns and it adheres to **S.O.L.I.D** design principles.
### A few reasons use DotNetRuleEngine ###
- Adheres to S.O.L.I.D
- Testable code.
- Encapsulates varying behavior. Such as business rules.
```csharp
PM> Install-Package DotNetRuleEngine
```
Nuget package available at: [DotNetRuleEngine](https://www.nuget.org/packages/DotNetRuleEngine "DotNetRuleEngine")
Get Started at: [DotNetRuleEngine Wiki](https://github.com/ayayalar/DotNetRuleEngine/wiki)
[](https://dev.azure.com/ayayalar/ayayalar/_build/latest?definitionId=1&branchName=master)
## Example
#### Model
```csharp
public class Order
{
public int Id { get; set; }
public decimal Total { get; set; }
public bool FreeShipping { get; set; }
}
Order order = new Order { Id = 1, Total = 79.99 };
```
#### Install DotNetRuleEngine
```install-package dotnetruleengine```
#### Create Rule(s)
*Create a rule to update FreeShipping attribute if the amount is greater than $50.00*
```csharp
public class QualifiesForFreeShipping: Rule
{
public override IRuleResult Invoke()
{
if (Model.Total > 50.0m)
{
Model.FreeShipping = true;
}
return null;
}
}
```
#### Invoke Rule(s)
```csharp
var ruleResults = RuleEngine.GetInstance(order)
.ApplyRules(new QualifiesForFreeShipping())
.Execute()
```