Background and Motivation
Microsoft.Extensions.Validation is intended and designed to be general purpose validation solution. Today, ValidateContext which is a core part of its interfaces has a ValidationContext property. This is coupling MEV with DataAnnotations strongly.
Proposed API
namespace Microsoft.Extensions.Validation;
[Experimental("ASP0029", UrlFormat = "https://aka.ms/aspnet/analyzer/{0}")]
public sealed class ValidateContext
{
- public required ValidationContext ValidationContext { get; set; }
+ public required IServiceProvider ServiceProvider { get; init; }
}
The default implementations that we provide that are coupled to DataAnnotations will then be responsible for creating the correct ValidationContext when needed.
Usage Examples
Same as today, except that we users will only set the service provider instead of creating the whole ValidationContext. We will be responsible for creating it when needed.
Alternative Designs
Risks
Background and Motivation
Microsoft.Extensions.Validation is intended and designed to be general purpose validation solution. Today,
ValidateContextwhich is a core part of its interfaces has aValidationContextproperty. This is coupling MEV with DataAnnotations strongly.Proposed API
namespace Microsoft.Extensions.Validation; [Experimental("ASP0029", UrlFormat = "https://aka.ms/aspnet/analyzer/{0}")] public sealed class ValidateContext { - public required ValidationContext ValidationContext { get; set; } + public required IServiceProvider ServiceProvider { get; init; } }The default implementations that we provide that are coupled to DataAnnotations will then be responsible for creating the correct ValidationContext when needed.
Usage Examples
Same as today, except that we users will only set the service provider instead of creating the whole ValidationContext. We will be responsible for creating it when needed.
Alternative Designs
Risks