PIAB + VAB Parameter Validation

Topics: Policy Injection Application Block, Validation Application Block
Jul 24, 2009 at 3:19 AM

I'm trying to use PIAB and VAB to validate the parameters(i have more thn one parameter in my method) of my method, but is not working. Can you give me the steps to do it? and also, is it possible to have a validator composition for a single parameter in method?

 

 

Jul 24, 2009 at 7:40 AM

Hi,

First you would need to create a interceptable class. With your method decorated by ValidationCallHandler attribute and the parameters with the validator attributes.

Here is a sample class:

    public class Person : MarshalByRefObject
    {
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public string MI { get; set; }

        [ValidationCallHandler]
        public void SetName(
            [StringLengthValidator(1, RangeBoundaryType.Inclusive, 0,
                RangeBoundaryType.Ignore, MessageTemplate = "Must be at least 1.")]
            string lastName,
            [StringLengthValidator(1, RangeBoundaryType.Inclusive, 0,
                RangeBoundaryType.Ignore, MessageTemplate = "Must be at least 1.")]
            string firstName,
            [StringLengthValidator(1, RangeBoundaryType.Inclusive, 0,
                RangeBoundaryType.Ignore, MessageTemplate = "Must be at least 1.")]
            string mi)
        {
            LastName = lastName;
            FirstName = firstName;
            MI = mi;
        }
    }

For the second question, As far as I've tried, composition works on the parameter validation using attributes but I haven't tried it using the config. so you could try that one to confirm.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com