Skip to content

Scandal-UK/FluentValidationLister

Repository files navigation

Build Status NuGet Downloads

FluentValidationLister.Filter

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.

🚀 Installation

  1. Install the package;

    dotnet add package FluentValidationLister
  2. In the ConfigureServices method of Startup.cs, include a call to AddFluentValidationFilter instead of AddFluentValidation.

    public void ConfigureServices(IServiceCollection services)
    {
        ...
    
        services.AddFluentValidationFilter();
    }
  3. In order for ASP.NET to discover your validators, they must be registered with the services collection. You must do this by calling the AddTransient method 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)

🧪 Try It Out

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.

About

A global action filter that provides serialised meta-data for a FluentValidation validator for any given endpoint. This allows for centralised validation on both client and server.

Topics

Resources

License

Stars

Watchers

Forks

Contributors