WebJobsOptionsFactory implementation ignores the "validations" parameter
See original GitHub issueBecause the implementation of the WebJobsOptionsFactory
ignores the validation, it does not perform the intended validation.
Repro steps
public class Startup : FunctionsStartup
{
public Startup()
{
var config = new ConfigurationBuilder()
.AddEnvironmentVariables();
Configuration = config.Build();
}
public IConfiguration Configuration { get; }
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddOptions<SampleOptions>()
.Bind(Configuration.GetSection("Sample"))
.ValidateDataAnnotations();
}
}
public class SampleOptions
{
[Required]
public string Value { get; set; }
}
Expected behavior
I expect the validation to run.
Sample:Value
key if the application settings are not set and OptionsValidationException
is thrown.
Actual behavior
No validation is performed and the property values are not checked.
Known workarounds
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
// Replace default implementation
builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory<>), typeof(OptionsFactory<>)));
}
}
Related information
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@fabiocav Any update on this? I was trying to validate options for azure functions v3 with no luck
Assigning this to the upcoming sprint