I heard that it is possible to create async validation attributes in ASP.NET WEB API 2, but I didn't find any examples. I would like to create a validation class like this one, but async way:
public class UserNameAvailable : ValidationAttribute
{
public override bool IsValid(object value)
{
var username = value as string;
if(username != null)
{
return !Database.UserExists(username); // must be async
}
return true;
}
}
By validation attribute, I am assuming you are referring to something like an ActionFitler attribute. In Web API 2, we do not yet have async version of methods in ActionFilter attributes yet. However, in the coming release we are supporting this feature.
Its still possible to create custom action filter attributes yourself which implement System.Web.Http.Filters.IActionFilter
, but I am wondering if you would rather wait for the next release. if this cannot wait, let me know and I can try something out for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With