Order in which validators are executed

Topics: Validation Application Block
Sep 23, 2011 at 2:24 PM

Hi,

I need to know, where I can find information about the order in which validator attributes with which a property of a class is decorated are executed.

For example, is ther a difference between the following two samples:

Sample 1:

ValidatorComposition(or)

PropertyComparison

NotNull

 

Sample 2:

PropertyComparison

NotNull

ValidatorComposition(or)?

 

Best regards

 

Chris

 

Sep 26, 2011 at 8:48 AM

Hi,

I'm not sure if this is going to be useful to you, but if you dig in the CHM file, under Unity Dependency Injection and Interception --> Interception with Unity --> Using Interception and Policy Injection --> Enterprise Library Call Handlers --> The Validation Handler, if you use ValidationCallHandlerAttribute with Unity, you must provide values for any mandatory parameters. One of those parameters is Order, and by default that parameter is set to 0, which means no explicit order is specified.

Hope this helps...

 

Sep 26, 2011 at 8:49 AM

Hi Chris,

Regarding with your example, it doesn't make a difference. The OR condition will still apply to both of your example. The place where you put the ValidatorComposition doesn't matter.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

 

Sep 26, 2011 at 9:56 AM

Thank you very much for your answers.

@CodeTrainer: it helps a lot to find a point from where it makes sense to explore this in deeper depth.

@AvandeSupport: Than I assume, that there is a (logical) calculus implemented. Can you tell me which, than I know, how the composition is done in very complex scenarios.

 

Best regards

 

Chris

Sep 27, 2011 at 12:50 AM

Hi Chris,

This is the built in behavior of the Validation Application Block. It aggregates all the validator and applies the OR condition to all validator. Let say you have:

ValidatorComposition(Or)
NotNullValidator
StringLengthValidator
RangeValidator
RegExValidator

it is just the same if you put the ValidatorComposition(Or) on another position like:

NotNullValidator
StringLengthValidator
RangeValidator
ValidatorComposition(Or)
RegExValidator

If any of the validator returns true, then the overall validation will become valid (IsValid = true).

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 27, 2011 at 7:53 AM

Hi Noel,

Thank you for this further explanation. Perhaps, the sample in my post is too easy. What I need to know is, how complex logical expression are evaluated:

ValidatorComposition(Or)

ValidatorComposition(Or)

ValidatorComposition(And)

NotNullValidator

StringLengthValidator

RangeValidator

RegExValidator

 

or:

Composition(And)

Composition(or)

NotNullVal

StringlengthVal

Compostion(Or)

RangeVal

RegExVal

 

In our real world, the expressions are more complex (not mentioned negation, using brackets, etc.). I would be very happy knowing where I can find information on how logical expression are constructed commonly (what typically is a description of the implemented (in this case logically) calculus, or, how your call it, the build in behaviour of the validation application block..

 

Sep 28, 2011 at 3:59 AM

Hi Chris,

Take a look at this; this is the C# Attribute specification page: http://msdn.microsoft.com/en-us/library/aa664616(v=vs.71).aspx

As it states (I am assuming that you are using C# for constructing your code), in the second paragraph of that article, the order in which attributes are specified is not significant. You can read through that article if you want to get a better understanding.

If you must know regarding how the attibutes are being arranged in Ent Lib 5, suffice it to say that there is a container class that contains the validators and that there is code that adds it to that container.

Hope this helps! :-)

Sep 28, 2011 at 8:07 AM

Hi CodeTrainer,

Thank you for answer. And yes, it helps. And again yes, your assumption that I use C# is right too.  I will have a look on how the validators are handled within their container.

Sep 28, 2011 at 9:00 AM

You're welcome; let me give you a head start on where you can look for the sln file:

C:\Users\<yourname>\Documents\EntLib50Src\Blocks\Validation

You can start here.

Sep 29, 2011 at 11:53 AM

I did so. My understanding on what is going grew tremendously.

Thank you very much, best regards

 

Chris