Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for simple rules-engine library in .NET [closed]

Does anyone know of a good .NET library rules library (ideally open-source)? I need something that can do nested logic expressions, e.g., (A AND B) AND (B OR C OR D). I need to do comparisons of object properties, e.g., A.P1 AND B.P1. (Ideally, I could compare any property -- A.P1 AND B.P2).

It should store the rules in a database (I've got a lot of simple configurable logic). And it should have a rule creation/management API. The management tool would have to inspect the instances to determine which properties are available and which constraints exist.

Thanks!


Oh, one more thing. As a rules-engine, I need to include the concept of Actions (Commands). These are what execute when the expression returns:

If (expression.Evaluation) { actions.Execute(); } 

So I see a rule as something like:

class Rule {     Expression Exp;     Actions[] Actions;     Run()      {          if(Exp.Evaluate())          {              foreach(action in Actions)              {                  action.Execute();              }         }      } } 
like image 227
Kurtz Avatar asked Oct 16 '08 13:10

Kurtz


People also ask

What is rule engine in C#?

The Rules Engine is a . NET C# project that validates business logic by defining a multiple rules for your data classes.

How do you implement rule engine?

Steps to implement Rule Engine Design patternWrite all rules in one method using if-then-else conditional statements. Step 2: Create classes for each rule. Create separate classes for each rule. Add a ShouldRun() method in each class file to determine whether the business rule has to be executed or not.

Where can you use rule engine?

For software developers, a rule engine is useful only if it liberates them from expressing the rule in the code. In order to avoid this pitfall, it is commonly accepted that we should use rule engines only if appropriate, or not use them at all. Over the past decades, that has become a self-fulfilling prophecy.

How does rule engine work?

A rule engine combines a set of facts that are inserted in to the system with its own Rule Set to reach a conclusion of triggering one or several actions. These rules typically describe in a declarative manner the business logic which needs to be implemented in our environment (which we assume rarely changes).


1 Answers

Agreeing with will I would say use something from the workflow engine family although not workflow. Examine System.Workflow.Activities.Rules Namespace a little bit - it's supported in .Net 3, and built into .Net3.5. You have everything in hand for free to use like you mentioned :

  • RuleCondition for conditions , RuleAction for actions

  • standardized format for describing metacode (CodeDom - CodeExpressions)

  • you can plugin any kind of complexity into that (to tell the truth except Linq and lambdas and so extension methods of some kind) via TypeProviders

  • there's a builtin editor for rule editing with intellisense

  • as the rule is serializable it can be easily persisted

  • if you meant to use the rules over a database scheme then via typeprovider it can be implemented too

For a starter : Using rules outside of a workflow

Ps.: we're using it extensively and there're much more in that namespace than you ever imagine -> a complete meta algorithm language

And the most important : it's easy to use - really

like image 58
Nicolai Ustinov Avatar answered Oct 09 '22 07:10

Nicolai Ustinov