Because the implementation of the WebJobsOptionsFactory ignores the validation, it does not perform the intended validation.
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; }
}
I expect the validation to run.
Sample:Value key if the application settings are not set and OptionsValidationException is thrown.
No validation is performed and the property values are not checked.
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
// Replace default implementation
builder.Services.Replace(ServiceDescriptor.Transient(typeof(IOptionsFactory<>), typeof(OptionsFactory<>)));
}
}
Assigning this to the upcoming sprint
Moving to sprint 86, but we're trying to get this into the 85 payload.
@fabiocav Any update on this? I was trying to validate options for azure functions v3 with no luck
@selMicrosoft Let me follow up with @soninaren on this issue.
Assigning this to @brettsam as he was recently impacted by the issue and worked on a fix.
Most helpful comment
@fabiocav Any update on this? I was trying to validate options for azure functions v3 with no luck