FluentValidationGenerator 0.2.1

dotnet add package FluentValidationGenerator --version 0.2.1
NuGet\Install-Package FluentValidationGenerator -Version 0.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentValidationGenerator" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentValidationGenerator --version 0.2.1
#r "nuget: FluentValidationGenerator, 0.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FluentValidationGenerator as a Cake Addin
#addin nuget:?package=FluentValidationGenerator&version=0.2.1

// Install FluentValidationGenerator as a Cake Tool
#tool nuget:?package=FluentValidationGenerator&version=0.2.1

FluentValidationGenerator

Nuget (with prereleases) Nuget Downloads GitHub Workflow Status

Maintainability codecov

A Code Generator for automatically generating FluentValidation Classes for .NET 7+ with predefined Rules.

The Generator uses MediatR Commands which inherit from the IRequest<> interface to automatically Generate Fluent Validator Classes.

Clean Architecture is the recommended Solution Architecture.

Plans

✅ Create Fluent Validators based on MediatR commands which follow the Clean Architecture

❌ Tests

❌ Create Fluent Validators for ASP.NET Core API's based on an OpenAPI specification

Usage

For Usage please refer to the Sample Project

FluentValidationGenerator.Generator takes the Assembly which contains the Commands and the Solution Folder as Parameters.

The easiest way to get your Solution Folder should be:

Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()))

This should result in:

var generator = new FluentValidationGenerator.Generator(
	typeof(CreateWeatherForecastCommand).Assembly,
	Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()))!);

generator.GenerateValidators();

Having defined Commands or Queries like the following:

public record CreateWeatherForecastCommand : IRequest<IEnumerable<WeatherForecast>>
{
    public required string[] Summaries { get; set; }

    public int TemperatureC { get; set; }

    public string? NullableString { get; set; }

    public required string NotNullableString { get; set; }

}

Should generate a File looking similar to the following Code, depending on the amount of Parameters

using FluentValidation;

namespace SampleNET7.Application.Messages.Commands;

public class CreateWeatherForecastCommandValidator : AbstractValidator<CreateWeatherForecastCommand>
{
  public CreateWeatherForecastCommandValidator()
  {
        
	RuleFor(t => t.Summaries).NotEmpty().WithMessage("Summaries Can not be Empty");

	RuleFor(t => t.TemperatureC);

	RuleFor(t => t.NullableString);

	RuleFor(t => t.NotNullableString).NotEmpty().WithMessage("NotNullableString Can not be Empty");

  }
}

The Generator will Generate an empty Rule for Nullable Properties or Value Types

<br>

Medium publication

<a href="https://www.buymeacoffee.com/DawnDevelop"><img src="https://img.buymeacoffee.com/button-api/?text=Coffee 😃&emoji=☕&slug=DawnDevelop&button_colour=17a4d3&font_colour=000000&font_family=Inter&outline_colour=000000&coffee_colour=FFDD00" /></a>

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 654 2/20/2023
0.2.0 209 2/20/2023
0.1.98 209 2/19/2023
0.1.97 209 2/19/2023
0.1.96 210 2/19/2023
0.1.95 211 2/19/2023
0.1.94 207 2/19/2023
0.1.93 205 2/19/2023
0.1.92 208 2/19/2023
0.1.91 215 2/19/2023
0.1.9 196 2/19/2023
0.1.7 204 2/19/2023
0.1.6 202 2/18/2023