Question

I'm looking for some engine that could handle situations like this:

I have an order object, with a customer object attached to it.
Rule:
If order.customer.id = 186 and order.industry = 23 then order.price = 100

I found NxBRE, but it seems overkill for this?

What are other people doing for situations like this? Just hardcode it or use Eval?

Was it helpful?

Solution

I also ran into this dilemma about two years ago, since it was something simple enough, didn't want to go overboard, and time constrain I ended up building something using customized logics interpretation to analyze ==, like, !=, >, etc, using Linq and strategy pattern as the base of the rules evaluation engine

Although if you know Windows Workflow Foundation, then apparently you can leverage its rules engine without having to actually use WF

OTHER TIPS

I also came across similar situations and thought of building my own engine instead of using existing, because when there is any change in my current logic or going on with new grounds it will be a great pain. If we get to know how the engine works we are open for any logic and the best thing is we can build solution to find the local and global optima!

Refer the below link which spoon feeds engine and helped me to create my new engine!

Click here for start up

If you are looking for a much simpler version and want to write your code like this...

    [TestMethod]
    public void GreaterThanRule_WhenGreater_ResultsTrue()
    {
        // ARRANGE
        int threshold = 5;
        int actual = 10;

        // ACT
        var integerRule = new IntegerGreaterThanRule();
        integerRule.Initialize(threshold, actual);

        var integerRuleEngine = new RuleEngine<int>();
        integerRuleEngine.Add(integerRule);
        var result = integerRuleEngine.MatchAll();

        // ASSERT
        Assert.IsTrue(result);
    }

... or like this...

[TestMethod]
public void GreaterThanRule_WhenGreater_ResultsTrue()
{
    // ARRANGE
    int threshold = 5;
    int actual = 10;

    // ACT
    var integerRule = new IntegerGreaterThanRule(threshold);

    var integerRuleEngine = new RuleEngine<int>();
    integerRuleEngine.ActualValue = actual;
    integerRuleEngine.Add(integerRule);

    // Get the result
    var result = integerRuleEngine.MatchAll();

    // ASSERT
    Assert.IsTrue(result);
}

... then maybe check out my blog where I build up a rule engine slowly. http://www.duanewingett.info/2015/01/21/SimpleCRuleEnginePart1TheRuleEngine.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top