Is there any information on how to configure a custom validator in the config tool

Topics: Validation Application Block
Mar 1, 2007 at 6:16 PM
I'm trying to figure out how to configure my custom validator in the EL config tool. I cannot find any mention of how to do this in the documentation. Can someone point me to it or let me know if it is possible.

Mar 1, 2007 at 8:23 PM
Hi Steve -

As with other extensibility points in EntLib, you can go down two paths when building new validators: untyped or typed configuration.

With untyped providers, you don't need to do any special work to integrate them into the config tool, but the catch is that the configuration is limited to a property bag with no validation or type checking. The Validation QuickStart has a few examples of this approach - the key thing is to put the correct ConfigurationElementType attribute on and to create a constructor that accepts a NaveValueCollection:

    [ConfigurationElementType(typeof(CustomValidatorData))]
    public class DivisibleByValidator : Validator<int>
    {
        private int divisor;
 
        public DivisibleByValidator(NameValueCollection attributes) : base(null, null)
        {
            divisor = Int32.Parse(attributes.Get("Divisor"));
        }
        
        // Implementation goes here
    }

If you want a strongly-typed configuration experience (ie a dedicated node type that exposes the exact properties you want), you'll need to build a runtime configuration type and a designtime configuration node and its associated plumbing. The validators supplied with the VAB all follow this approach so you can look at this code for clues.

BTW both approaches to building providers (including validators) are largely automated by the Application Block Software Factory.

HTH
Tom