Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wellingtonjhn/1f240e4f718364da83862a0fd4c79ff1 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/1f240e4f718364da83862a0fd4c79ff1 to your computer and use it in GitHub Desktop.
MySettingsValidator PostConfigureOptions implementation
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)}");
}
}
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