Suggestion on additional VAB attribute

Topics: Validation Application Block
Mar 7, 2007 at 10:57 PM
Hello,

I would suggest an additional VAB attrubute to be implemented which doesn't allow to apply any Validators from configuration.

For instance,

public class Person {

DenyApplyingValidator
public string Age
{ get {}; set {}; }

}

It means that all Validators I apply to Person class in configuration will not work at all. Just no way to change the logic and fail validation using this property.

I've posted this as a suggestion to Issue Tracker http://www.codeplex.com/entlib/WorkItem/View.aspx?WorkItemId=8746

Thanks,
Leonid
Mar 7, 2007 at 11:06 PM
Hi Leonid -

Thanks for the suggestion. Could you give an example of a scenario where this would be needed?

You can already specify that you only want to load validators from attributes (or from configuration) like this:
Validator<Person> v = ValidationFactory.CreateValidatorFromAttributes<Person>();
I'm not sure I understand whether your scenario is the same as this or not.

Tom
Mar 7, 2007 at 11:49 PM
Hi Tom,

I see that I can handle validators from both sources separately, but it leaves the way to apply one validator through an attribute and another through configuration to the same property. For instance the first will pass, the second will fail and I have to implement an additional logic sorting out the results I got from ValidateFromConfiguration(), find out exactly validators were applyed for Age property and don't take them into account. So I have two IsValid values and cannot rely on IsValid from config.

The idea I'm trying to come up is that validators for a class still can be applyed from both sources, that's ok, I handle validation results in a single Validate() call as usual, but there is a single property (for instance) for which I just cann't apply any validators from configuration. I really can write any rule for it in config but they don't work.


public class Person {

public string Name
{ get {}; set {}; }

DenyApplyingValidator
public string Age
{ get {}; set {}; }

public string Country
{ get {}; set {}; }

}

then I validate a class

ValidationResults results = Validation.Validate<Person>( person );

check IsValid and don't go ahead if it is invalid.

In this scenario I can change the logic through validators - I can restrict access denying persons with not english names, accept only who is from US, change these behaviors later, but cann't do anything with Age and don't allow this to the others.

Thanks a lot!
Leonid