Add built in support for validating options #227
Description
I just made an Option
class that takes strings that are required to be a certain format. I would like the configuration to fail after hydration if the values provided are invalid. A good example is if you need an email (ignoring how hard it can be to validate emails).
Today I can solve this by creating an IPostConfigureOptions
that resolves to a ValidateOptions
class that checks if the options in question implement an IValidatable
interface, and if so calls Validate()
.
It would, however, be preferable if I knew that validation always ran last (after all post configure handlers - if any). Therefore I suggest adding first class support for IValidateOptions
which runs after runs after IPostConfigureOptions
. This interface would behave the exact same as IPostConfigureOptions
, except it would be guaranteed to run after all IPostConfigureOptions
.
It can also be discussed whether or not default implementation that does something similar to my described ValidateOptions
class would be useful.