How do you fill about validation block?

Topics: Validation Application Block
Jun 11, 2007 at 5:39 PM
Edited Jun 11, 2007 at 5:48 PM
Hi all!

I'm basically interested to hear about subj from you.

It's sad to say but I'm frustrated and disappointed.
I've spend some time with validation block and think it's usability is kind of limited.
I guess it's not about validation classes, but more about the way how configuration is done.

First of all there is no easy way to create trully dynamic validators based on configuration data. Someone may argue that it's doable, but think how difficult it will be. What is the purpose of such framework then?

Let me highlight some points which IMHO need to be reconsidered.

1. There is no way to enable/disable validator in configuration. I can do that by removing validators from sets, but it's kind of heavy editing. It must be simple as setting enabled attribute. I don't want to go through full test cycle, just because I disabled validator. Disabling validator defined with attribute from config file will be nice as well. I guess one can do that with derived classes, but this requirement is so basic...

2. There is no way to get validator by name, only rule set.
3. There is no way to refence one validator from another one or from rule set. See above.
Forgive me, IMHO, it is bad approach, because is to coarse. What I would like to see is defining rules and referencing them from rule sets, possibly different. Why do i need define same regexp validator on every class that have let say phone number? Isn't it more natural define validator once and reference it from everywhere?

4. Validator is black box. This is good from one side, but bad If i need to do something on the fly. This is especially true for composites.

4. Filtering validation results by tag name is neat feature, but let me ask why we cannot filter validators before they even executed? Isn't it the proper way to reduse amount of work in server side environment? Why do i need to execute each and every validator even if i know that I will throw it's result later?

5. Asking facade to validate object is like looking for troubles. If rule set is not defined then no exception is trown! Man, you are simply valid all the time! There is no infostructure created to check is rule set exists. Well, Configuration namespace might help, but again I would like to work in the boundaries of framework.

6. I guess a lot of flexybility might be added with Policy Injection block, but for the moment it seems to be even more complicated. Simple things must stay simple.

Here I must confess.
My current knowledge and understanding of .NET and EntLib is kind of very limited right now, so please don't be too sarcastic. Please advise if possible and provide your opinon and contrarguments.
Jun 12, 2007 at 10:20 PM
I must say I agree with most of your points towards the VAB ...except the conclusion. I think the VAB is excellent in what it does, but unfortunally has a few shortcommings right now, to make it a truly powerful framework. I do consider it an upgrade vs the previous validation framework I used, which was a custom tailored edition of the CSLA validation block.

My two top feature requests would have to be:

1. Cross property validation where property Y can be validatd as part of an And/Or expression on property X. (ie conditional validation).
2. Being able to define validators through configuration and then apply them where needed.
Jun 13, 2007 at 2:02 AM
Wow! Finally!

I thought nobody use it... ;-)

I have a couple of choices on my hands right now. EntLib and Spring.NET.
I invested some time in investigation of EntLib and you how do I fill about it.

I still continue to dig it, but Spring.NET looks way more natural for me, at least on the paper.
They have conditions, references, actions and groups. Everything is done in consistent manner. The only problem is lack of step-by-step samples, so I cannot get it to work yet.

See http://opensource.atlassian.com/confluence/spring/display/NET/Validation+Framework
Jun 13, 2007 at 3:03 PM
Edited Jun 13, 2007 at 3:04 PM
POSSIBLE DESIGN PROBLEM.

I'm kind of figured out how to derive conditional validator from the custom one. Thought it still will be nice to have it in the base classes and supported by configuration. Unfortunatelly I haven't enough time to do that.

But then I hit another design problem. EntLib has composites, which are not suted to work with conditional validators. How so?
Let say I have ORed conditional validators for US states. Composite holds AZ, FL, OH, WA. My data is for OH. So, AZ validator does nothing, it's simply skip, which is kind of logical, isn't it? What happens to OR composite? Right - it is valid now. But it didn't performed real validation yet.

Conclusion - disabled validator is not the same as valid one. Now In order to make it happen I need override MS composites...
The simplest solution I see is to play with validation results. Let say add fake results and then extract them before real processing.

Basing ValidationResults.IsValid on count of results is kind of logical... but IMHO fragile.