Skip to content

jej666/DotNetRuleEngine

 
 

Repository files navigation

DotNetRuleEngine

(Rule Based Software Development)

S.O.L.I.D COMPLIANT

DotNetRuleEngine allows you to write your business logic as series of rules to keep your code clean and structured. Supports both synchronous and asynchronous execution and it is S.O.L.I.D compliant.

A few reasons use DotNetRuleEngine

  • S.O.L.I.D
  • Separation of Concern.
  • Encapsulates varying behavior. Such as business rules.
  • Easy to maintain.
  • Testable code.
PM> Install-Package DotNetRuleEngine

Nuget package available at: DotNetRuleEngine

Get Started at: DotNetRuleEngine Wiki

Model

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

public class QualifiesForFreeShipping: Rule<Order>
{   
    public override IRuleResult Invoke()
    {
        if (Model.Total > 50.0m)
        {
            Model.FreeShipping = true;
        }
        
        return null;
    }
}

Invoke Rule(s)

var ruleResults = RuleEngine<Order>.GetInstance(order)
    .ApplyRules(new QualifiesForFreeShipping())
    .Execute()

About

DotNetRuleEngine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%