10

I am currently writing a .net application with c# and want to check a number of rules and based on passing or failing the rules, perform an action. So I am looking to implement a generic solution that I can reuse adhering to good oop principles. This has lead me to the conclusion that I need to write a rules engine.

I have good knowledge of c# but this is the first time I have needed to write a rules engine so as part of my research in to the design and development of such, I am looking for any tips regarding the creation of such an engine. What would be great further would be any examples out there that I could look at? Any c#/.net rules engine applications? What layer in a typical 3 tier architecture should such reside at? I had a quick look on the codeplex and google code but none jumped out at me! So some direction would be great.

amateur
  • 43,371
  • 65
  • 192
  • 320

2 Answers2

3

Actually .NET has a top-notch rules engine meant to be used with workflows (as it is designed to be) but can be used outside of workflows easily: You should see "Windows Workflow Foundation Rules Engine" and inspect the System.Workflow.Activities.Rules namespace.

Learning how to use rules outside of workflows takes only a bit of googling.

Edit: If you want to inspect the architecture, here is two open-source prebuilt engines:

Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80
  • 1
    I know this sounds like terrible hubris but I've found the WF rules library to be anemic and practically unusable compared to a well-designed, customized domain-specific engine. It really depends on the application, of course, but I don't know if I'd be so quick to recommend it. – Aaronaught May 14 '11 at 02:27
  • I use it all the time with my workflows for slow-paced industrial control apps, which gave me the impression that it is one of the most pragmatic implementations. But maybe that's because I'm so acquainted with it. But I know, this is more like a typical xUnit vs MSUnit argument.. – Teoman Soygul May 14 '11 at 02:37
  • 1
    Perhaps. All I know is that every time I've tried to use WF (or WF rules), I've always ended up throwing my hands up and saying "Why don't I just *write the code* instead of shoehorning it into this thing?" I'm not comparing WF to other workflow engines, I'm sure they're all fine, I guess what I'm saying is that most if not all OTS rules engines are entirely too generic to offer much of an advantage over simple code+configuration. Maybe it's just my inexperience/bad experience talking. – Aaronaught May 14 '11 at 03:05
0

Building and implementing your own rules engine can be a very difficult task with many things to consider. The biggest problem you will face is trying to decide which rules to fire and when. Not giving this the proper care can lead to performance problems within the implementation. I would highly recommend focusing in on the business problem and providing your subject matter experts (SME’s) with the ability to define and maintain their own rules. There are many good commercial products that do this; the one I have successfully implemented multiple times is www.inrule.com. They have a nice set of products that can help solve simple and complex problems. Hopefully this helps.