views:

258

answers:

1

For a large application that will be developed, we are in the process of selecting a Validation framework. Although the Workflow Rules engine is not strictly a Validation framework, it can be used by itself without using the Workflow foundation. It appears to give flexibility of specifying the rules in a database that is used at runtime. However, it appears that you cannot specify rules in the code.

If greater flexibility is one of the requirements (not necessarily that the rules need to be edited by Business analysts), which of the two would you prefer and why?

+2  A: 

It quite matters in what your exact requirements are. 'Being flexible' is by itself not a good requirement, because it isn't measurable. It's very subjective if something is flexible.

I'm not familiar with Microsoft Business Rules Engine, so I can't comment on that. I am however very familiar with the Microsoft Enterprise Library Validation Application Block (VAB) and it has served me well over the last year. It has several features that make it flexible for the situations I’m dealing with:

  • It allows both defining validation declarative (using attributes) and using an external configuration file (which is very useful when your entities are generated).
  • It contains a set of default validators that can be used and custom validators can be written.
  • It allows validation of single properties and allows you compare multiple properties as a group (by using self validation or custom validators).
  • It allows validating objects in isolation, as well as object graphs.
  • It allows you to define multiple 'rule sets' which for instance allows you to define an set of hard errors and a set of warnings.

VAB (or the Enterprise Library as a whole) allows you write a custom configuration source (IConfigurationSource) which allows you to define your business rules wherever you want. So in theory you could store them in the database, however you will have to write such configuration source yourself, and this will be quite some work. Especially when you want your business analysts to be able to define validations and update the database with some sort of editing tool, it think this will be quite hellish to accomplish with VAB.

If there really is a requirement of the business people to write those rules themselves, hopefully you got process supporting this requirement. For instance, how are they going to test whether their changes are correct? You wouldn’t want your business analysts to make changes directly to the production database.

But please give this a thought. If the rules are going to be tested, I expect those rules not to be changed directly in your production database, otherwise you would be testing after the fact. So, the analysts would be changing the rules in their own environment and you’d probably be publishing the new rules from this environment to a test environment, and later on to acceptation environment and eventually to a production environment. And if you’re taking these steps, should you still use a database to store those business rules? Using a configuration file would make it much easier than using the database. Deployment would simply be a file copy instead of copying the content of multiple tables from database to database.

I'm interested in what others have to say about the validation frameworks they know well.

Steven
@Steven - The Rules engine has some features such as prioritizing rules and forward chanining that are not supported by VAB. I am looking for a feature rich framework and am not really sure what VAB supporsts that's not supported by WF Rules
@Steven - With VAB, where do you put in validation such as "If this ID does not exist in the database, then validation is successful else its not". Does the DB access logic go as a part of the class (maybe in SelfValidation method)?
@User102533: This comment field is too short to answer your question "where does complex db specific validation logic go", but wrote about that on another thread here on SO. I hope it answers your question: http://stackoverflow.com/questions/2258513/validation-framework-in-net-that-can-do-edits-between-fields/2259062#2259062
Steven
@Steven - Is it possible to in the Custom Validator get a reference to an object other than the one that you are validating? A use case could be "Ensure Order.Qty > 10 when Employee.Status = 'Premium'" If I create a CustomValidator for Order.Qty, in the DoValidate method, how would I get reference to the Employee object?
@User102533: It depends. When you create a custom validator for Order, you can access both Qty and Customer. If you need validation based on the context, read this article: http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=47.
Steven
@Steven - Can you please explain how I would have access to Employee in a Customvalidator built for Order? I understand I can get a reference to the Order by typecasting the currentTarget object, but I am not sure how to get reference to a Employee object.I read the article you linked but I am not very clear what "validation based on the context" really means. Maybe a short example will help. Thanks! Excellent article series.
@user102533: It is difficult to explain it here as a comment. Perhaps we should take the discussion somewhere else? Mail perhaps? Send me a mail to ‘steven at [the domain where you found my article]’. I will be happy to answer your question.
Steven
@Steven - I've emailed you. Thanks.
Hmm ... I am curious to know about the email interaction you guys had. Can you please publish the email trail as a separate answer (so that there is enough space for you to paste)?
Kabeer
@Kabeer: It won't be possible to post the conversions here, because it is simply too much. But if you send me a mail, I'm happy to answer your questions.
Steven
@Kabeer: Or ask your questions here again at SO, of course.
Steven