https://github.com/juntossomosmais/jsm.fluentvalidation.aspnet.asyncfilter
ASP.NET filter that performs async validation using FluentValidation
https://github.com/juntossomosmais/jsm.fluentvalidation.aspnet.asyncfilter
aspnetcore hacktoberfest validation-library
Last synced: 4 months ago
JSON representation
ASP.NET filter that performs async validation using FluentValidation
- Host: GitHub
- URL: https://github.com/juntossomosmais/jsm.fluentvalidation.aspnet.asyncfilter
- Owner: juntossomosmais
- License: mit
- Created: 2021-11-17T19:13:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-13T23:30:22.000Z (over 3 years ago)
- Last Synced: 2025-03-21T11:02:53.427Z (about 1 year ago)
- Topics: aspnetcore, hacktoberfest, validation-library
- Language: C#
- Homepage:
- Size: 120 KB
- Stars: 10
- Watchers: 42
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# JSM.FluentValidation.AspNet.AsyncFilter
[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_FluentValidation.AspNet.AsyncFilter)
[](https://sonarcloud.io/summary/new_code?id=juntossomosmais_FluentValidation.AspNet.AsyncValidationFilter)
[](https://www.nuget.org/packages/JSM.FluentValidation.AspNet.AsyncFilter/)
[FluentValidation documentation](https://docs.fluentvalidation.net/en/latest/async.html) states:
>You should not use asynchronous rules when using automatic validation with ASP.NET as ASP.NET’s validation pipeline is not asynchronous. If you use asynchronous rules with ASP.NET’s automatic validation, they will always be run synchronously.
This library provides an ASP.NET filter that performs async Validation using FluentValidation.
## Get Started
To use the filter, first install the NuGet package:
```
dotnet add package JSM.FluentValidation.AspNet.AsyncFilter
```
Then, it's necessary to register the filter on the `ConfigureServices` portion of the `Startup.cs`.
```c#
services
.AddControllers
.AddModelValidationAsyncActionFilter();
```
The next step is to register the validators of the API:
```c#
services
.AddScoped, MyClassValidator>>();
```
Or use [automatic registration](https://docs.fluentvalidation.net/en/latest/di.html#automatic-registration).
## Customization
If also possible to apply the filter only to controllers that contains the [`ApiControllerAttribute`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.apicontrollerattribute).
```c#
...
.AddModelValidationAsyncActionFilter(options =>
{
options.OnlyApiController = true;
});
```
This way, other controllers requests without the attribute will be ignored.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md).