Skip to content

Remove DataAnnotations dependency in MEV public API #67550

Description

@Youssef1313

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

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIs

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions