We are using version 4.1 of the validation application block. I am relatively new to it so I was wondering if it had the ability to either abstract out the configured namespaces and assemblies or otherwise provide proper validation of their existence?
We had an issue recently where someone moved a class and didn't update the validation configuration file with the new namespace. As a result the validations were no longer being applied to the object. The application block seems to just ignore the discrepancies. Unfortunately this was not caught during the normal QA cycle. Is there any built in way to protect ourselves from this type of change in the future? What I did in the interim is load up the config xml, extract out all the assemblies and defined namespaces and validate that they all exist.
Write a set of unit tests to see if objects get validated correctly.
Another option is to build up the vab configuration dynamically in a fluent way. This will give you compile time support and refactoring safety.
There is only one problem with this: vab has no support for this out of the box. You will have to write this yourself. Creating a VAB contrib project with such feature is on my todo list for years already, but I never had the time to do this. It isn't that hard though. Here is the code I wrote a few years back (but never got the time to finish it):
Using this code you can define your configuration fluently as follows:
The
ValidationConfigurationBuilder
is aIConfigurationSource
and you can supply it to theValidationFactory.CreateValidator
instance. Here's an example: