FluentValidationLister is a .NET library that extracts and lists rules defined using FluentValidation.
It provides introspectable metadata to the front-end that helps developers and client apps understand which validations/types apply to their models — useful for UI rendering, documentation, API consumers and client validators.
-
Install the package;
dotnet add package FluentValidationLister
-
In the ConfigureServices method of Startup.cs, include a call to
AddFluentValidationFilterinstead ofAddFluentValidation.public void ConfigureServices(IServiceCollection services) { ... services.AddFluentValidationFilter(); }
-
In order for ASP.NET to discover your validators, they must be registered with the services collection. You must do this by calling the
AddTransientmethod for each of your validators. Adding all validators in a specified assembly is not supported.services.AddFluentValidationFilter(); services.AddTransient<IValidator<Person>, PersonValidator>(); // (repeat for every validator)
The middleware is invoked by appending ?validation=1 to any endpoint (simply use {} for POST/PUT requests). Explore the FluentValidationLister.WebApiSample to see the library in action. It also allows single-field validation by appending ?validate={fieldName} to the URL.
The sample includes an ASP.NET Core API and a browser-based form that demonstrates how the validation rules can be consumed dynamically.