We have a business requirement to let power users edit rules for insurance rates and enrollments. We need a web ui that lets them say "this product is only for people <55 unless they are from Texas and own a poodle" or whatever. Edit for clarification: Insurance is insane. The rules differ from product to product, state to state and change constantly.
We looked at a couple of rules engines but the commercial ones are 100K+ and the open source ones don't seem um, finished. Windows Workflow works if we create the rules ahead of time, but building them at runtime seems to require bypassing code access security. That's scary.
Are we nuts to reinvent this wheel? Is there a better alternative for .net?
The Rules Engine is a . NET C# project that validates business logic by defining a multiple rules for your data classes.
With Azure Front Door (classic) Rules Engine, you can create a combination of Rules Engine configurations, each composed of a set of rules.
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.
I do not think that the evaluation of the rules will be the challenge. I think that the greater challenge is to parse the rules that the user can enter. For parsing the rules you should consider to create some DSL. Martin Fowler has some thoughts about this here. Then maybe ANTLR then might be worth a look.
For the evaluation part: I work in the finance industry and there are also complicated rules, but I never had to use a rule engine. The means of an imperative programming language (in my case C#) were (until now) sufficient. For some occasions I was considering a rules engine, but the technological risks(*) of a rule engine were always higher than the expected benefits. The rules were (until now) never that complicated, that declarative programming model was needed.
If you are using a object oriented language you can try to apply the Specification Pattern. Eric Evans and Martin Fowler have written a more detailed explanation, which you can find here. Alternatively you can write your own simple rule engine.
(*) Footnote: Somehow you will need to embed the rule engine into your application which is very likely written in some object oriented language. So there are some technological boundaries, which you have to bridge. Every such bridge is a technological risk. I had once witnessed a Java web application using a rule engine written in C. At the beginning the C program sometimes produced core dumps and tore down the whole web application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With