Design flaw concerning PropertyComparisonValidator

Topics: Validation Application Block
Dec 12, 2010 at 1:06 PM

I believe I encountered a design flaw in VAB 5.0 around the use of the PropertyComparisonValidator. This validator behaves in a sense the same as the SelfValidation method, because it needs a instantiated object of a type to be able to do its validation. The PropertyComparisonValidator, data and its attribute however, haven't been marked in any special way in the framework. Because of this, the GetPropertyValidator method of the PropertyValidationFactory doesn't skip the PropertyComparisonValidator, when building a validator for a single property. This is a problem, because the PropertyValidationFactory is used mostly by the integration assemblies (for WPF, ASP.NET and WinForms) and these integration assemblies never validate complete entities, but only values of single properties. For that same reason these assemblies do not trigger the SelfValidation attributes.

I consider this a design flaw, because now our domain validations are dependent on the type of validation we do in the presentation layer. We have to be careful not to use any PropertyComparisonValidator attributes when there is a possibility of using one of the integration libraries in the future.

IMO the PropertyComparisonValidator should be considered an instance level validator (just like the SelfValidation) that should not be included in the aggregation of validators that is created by the PropertyValidationFactory.

Of course, changing this in a future release is a breaking change, because the PropertyValidationFactory is a public type. I think however, that leaving it the way it is, is actually worse than introducing this breaking change, because this design flaw causes us to have to change domain validations based the chosen presentation technology and the other way around, thus causing the validation layer to become a leaky abstraction.

I hope this makes sense.

Dec 13, 2010 at 9:41 AM

Hi dot_net_junkie,

Thanks for sharing your thoughts on this. We'll check with the EntLib team's input on this since we're not in the best position to answer this.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.

Feb 7, 2011 at 10:54 PM

Thank you for your suggestion. We will consider it in the future version of the Validation Application Block.