For full setup see:
How to use IOptions for Config Binding
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
...
services.AddOptions<MyConfigModel>()
.Bind(Configuration.GetSection("MyConfigValues"))
.ValidateDataAnnotations();
...
}
...
}
public class MyConfigModel
{
[RegularExpression(@"^[a-zA-Z''-'\\s]{1,40}$")]
public string Hello { get; set; }
}
When getting the config value that doesn't match the regex: