Archive for the ‘Castle’ Category.
September 18, 2008, 10:09 pm
Been pretty busy at work, so short post.
I’ve added a facility in Castle contrib for validating method parameters using Castle Validator. The goal is to eventually allow have this used for validate parameters in Monorail, but right now I’m using it to do input validation for web service parameters. I wrote up a brief blurb on how to use it here: http://using.castleproject.org/display/Contrib/Castle.Facilities.MethodValidator. Should be pretty self explanatory.
If anyone finds any issues, let me know.
August 28, 2008, 8:30 pm
I have contributed a couple of enhancements to Castle.Components.Validator that have been committed to the trunk. Besides using attributes, validations can now be supplied in code using the [ValidateSelf] attribute:

Each of the above validations *could* be done by using an attribute and a custom validator, but expressing validations in code is much simpler for these types of one off validations. You can have as many methods decorated with [ValidateSelf] on an object you want as long as they have the above method signature (void return and one ErrorSummary parameter). You can also specify the RunWhen and ExecutionOrder just like regular validators.
The second enhancement is the IValidationContributor interface. This allows you contribute to the validation of an object beyond the default validation. The interface is fairly simplistic:

You can extend AbstractValidationContributor so that you can perform initialization for a given type. The SelfValidationContributor implements the logic for recognizing and executing the self validation feature above. You can write custom contributors that can be injected into the DefaultValidatorRunner for things like retrieving validations from the container and invoking them on the object.
Enjoy!