Last active
September 8, 2018 03:57
-
-
Save wellingtonjhn/1f240e4f718364da83862a0fd4c79ff1 to your computer and use it in GitHub Desktop.
MySettingsValidator PostConfigureOptions implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MySettingsValidator : IPostConfigureOptions<MySettings> | |
| { | |
| public void PostConfigure(string name, MySettings options) | |
| { | |
| if (options.Validate()) | |
| { | |
| return; | |
| } | |
| throw new InvalidOperationException($"Invalid {nameof(MySettings)} options. {string.Join(",", options.ValidationResult)}"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Startup | |
| { | |
| // ... código omitido | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| services.AddSingleton(Configuration); | |
| services.Configure<MySettings>(Configuration.GetSection("MySettings")); | |
| services.ConfigureOptions<MySettingsValidator>(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment