-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Arif Yayalar (@ayayalar) edited this page Aug 2, 2019
·
8 revisions
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.
- Adheres to S.O.L.I.D
- Testable code.
- Encapsulates varying behavior. Such as business rules.
- (A)synchronous/Parallel support
- Reactive support
- Built-in DI
Nuget package available at: DotNetRuleEngine
PM> Install-Package DotNetRuleEngine
Create a rule to update FreeShipping attribute if the amount is greater than $50.00
public class QualifiesForFreeShipping: Rule<Order>
{
public override IRuleResult Invoke()
{
// Order instance available through the model property.
if (Model.Total > 50.0m)
{
Model.FreeShipping = true;
}
return null;
}
}
Order order = new Order { Id = 1, Total = 79.99 };
// Pass order instance to RuleEngine.
var ruleResults = RuleEngine<Order>.GetInstance(order)
.ApplyRules(new QualifiesForFreeShipping())
.Execute()
public class Order
{
public int Id { get; set; }
public decimal Total { get; set; }
public bool FreeShipping { get; set; }
}
Synchronous Rules |
Asynchronous Rules |
Parallel Rules |
Reactive Rules |
Proactive Rules |
ExceptionHandler Rules |