-
Notifications
You must be signed in to change notification settings - Fork 67
Add built in support for validating options #227
Comments
I think this is something similar with what you're looking for. Am I right? |
This feature is on our radar, I'm not sure when we will add first class support for validation of options, (today we roll our own validation pattern in Auth), but sooner or later this seems like something Options should support in a first class way. |
Some time ago I was thinking about being able to validate options. In my opinion, this is really useful feature - being able to validate options and handle invalid scenarios. Moreover, I was looking for possibility to validate all registered options at start-up time (not only when it will be required) - this is just a simple early problem detection. For that purpose I have created PR (#171) which adds the possibility to configure the validation of option that's going after all configure steps. And that PR introduces the possibility to validate all options at the start up time. |
This issue was moved to dotnet/aspnetcore#2388 |
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 aValidateOptions
class that checks if the options in question implement anIValidatable
interface, and if so callsValidate()
.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 afterIPostConfigureOptions
. This interface would behave the exact same asIPostConfigureOptions
, except it would be guaranteed to run after allIPostConfigureOptions
.It can also be discussed whether or not default implementation that does something similar to my described
ValidateOptions
class would be useful.The text was updated successfully, but these errors were encountered: