Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Add built in support for validating options #227

Closed
Alxandr opened this issue Aug 23, 2017 · 4 comments
Closed

Add built in support for validating options #227

Alxandr opened this issue Aug 23, 2017 · 4 comments

Comments

@Alxandr
Copy link

Alxandr commented Aug 23, 2017

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.

@MaKCbIMKo
Copy link

I think this is something similar with what you're looking for.

Am I right?

@HaoK
Copy link
Member

HaoK commented Aug 25, 2017

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.

cc @divega @ajcvickers @davidfowl

@MaKCbIMKo
Copy link

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.

@aspnet-hello
Copy link

This issue was moved to dotnet/aspnetcore#2388

@aspnet aspnet locked and limited conversation to collaborators Jan 1, 2018
@aspnet-hello aspnet-hello removed this from the Backlog milestone Jan 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants