-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eager options validation only validates the last named option #51171
Comments
Tagging subscribers to this area: @maryamariyan Issue DetailsDescriptionRepro: using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System.ComponentModel.DataAnnotations;
namespace Test
{
class Program
{
static Task Main() => Host.CreateDefaultBuilder().ConfigureServices(s =>
s.AddOptions<M>().ValidateOnStart().Validate(m => m.A < 0, "A should be negative").Services
.AddOptions<M>("y").ValidateOnStart().Validate(m => m.A > 0, "A should be positive")).RunConsoleAsync();
}
class M
{
public int A { get; set; }
[Required]
public string S { get; set; }
}
} Expected: Actual:
I think the dictionary that stores the validation actions should have a tuple key: runtime/src/libraries/Microsoft.Extensions.Hosting/src/OptionsBuilderExtensions.cs Line 34 in 5d0817a
Should be something like: vo.Validators[(typeof(TOptions), optionsBuilder.Name)] = () => options.Get(optionsBuilder.Name); Configuration6.0.100-preview.3.21202.5 / Linux (WSL)
|
Yes that looks right. |
@davidfowl, could you please clarify? Current behavior or proposed one looks right? |
Proposed |
Description
Repro:
Expected:
AggregateException
with both "A should be negative" and "A should be positive" exceptionsActual:
Only the last validation runs
I think the dictionary that stores the validation actions should have a tuple key:
runtime/src/libraries/Microsoft.Extensions.Hosting/src/OptionsBuilderExtensions.cs
Line 34 in 5d0817a
Should be something like:
Configuration
6.0.100-preview.3.21202.5 / Linux (WSL)
The text was updated successfully, but these errors were encountered: