Mvc: Feature Request: AsyncValidationAttribute

Created on 17 May 2018  路  5Comments  路  Source: aspnet/Mvc

Is this a Bug or Feature request?:

Feature Request

Steps to reproduce (preferrably a link to a GitHub repo with a repro project):

Proposed API:

public class MyValidationAttribute : AsyncValidationAttribute
{
    protected override async Task<ValidationResult> IsValidAsync(object value, ValidationContext validationContext, HttpContext httpContext)
    {
        var db = httpContext.RequestServices.GetRequiredService<MyDbContext>();
    }
}

Description of the problem:

Introduce new validation attribute for asynchronously validating a model. The method should:

  • Be async to allow await-ing asynchronous validations. For example: against a database table.

  • Accept HttpContext as parameter, to allow implementer to pull application services.

This feature will allow organizing validations purely in attributes, instead of having some validations in attributes and some in controllers.

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All:

-

enhancement

All 5 comments

Thanks for contacting us, @ryanelian.

@glennc is this something we'd be interested in doing?
/cc @rynowak, @danroth27

Hi. Thanks for contacting us.
We're closing this issue as there was no much community interest in supporting async validation. May the situation change in the future we may reconsider this.

Hello.

Please reconsider, we would benefit from this too.

Thanks!

Up, we had some cases in which we needed async validation too.

I am also wanting this.

Was this page helpful?
0 / 5 - 0 ratings