EutonTechnologies.ValidationRules.Types 1.0.1

Suggested Alternatives

CleanArchitecture.ValidationRules.Types

Additional Details

Changed namespace

dotnet add package EutonTechnologies.ValidationRules.Types --version 1.0.1                
NuGet\Install-Package EutonTechnologies.ValidationRules.Types -Version 1.0.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="EutonTechnologies.ValidationRules.Types" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EutonTechnologies.ValidationRules.Types --version 1.0.1                
#r "nuget: EutonTechnologies.ValidationRules.Types, 1.0.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 EutonTechnologies.ValidationRules.Types as a Cake Addin
#addin nuget:?package=EutonTechnologies.ValidationRules.Types&version=1.0.1

// Install EutonTechnologies.ValidationRules.Types as a Cake Tool
#tool nuget:?package=EutonTechnologies.ValidationRules.Types&version=1.0.1                

Clean-Architecture-Fluent-Validation

Source Generator to automatically validate persistence layer data annotations without manual duplication.

Overview

This source generator was inspired by Clean Architecture. One of the problems that we have encountered is needing to have both database constraints and input constraints. We wouldn't want to create a database with a string with no max length when the field calls for only a few characters. We also wouldn't want to have to keep both the persistence entity and the data transfer object in sync for these max character lengths.

So EutonTechnologies.ValidatonRules.Types.Analyzers was born and it will automatically generate the Fluent Validation files that you can call to validate the persistence layer's object. In order to allow for the most flexibility, Fluent Validation's abstract validator isn't generated automatically but rather the rules that can be easily called by your AbstractValdiator for the dto. See Usage for more information.

Installation

$> dotnet add package EutonTechnologies.ValidationRules.Types.Analyzers

Usage

Add FluentValidation validator

//Application Layer Code
namespace MoviesExample.Application.Genres.Commands.CreateGenre
{
	[ExtendValidation(typeof(Genre))]
    public record CreateGenreCommand : IRequest<CreateGenrePayload>
    {
        public string? Name { get; init; }
    }
    public class CreateGenreCommandValidator : AbstractValidator<CreateGenreCommand>
    {
        public CreateGenreCommandValidator()
        {
            RuleFor(v => v.Name).Name();//The Name method is created automatically by the source generator.
        }
    }
}
//Domain Layer Entities

namespace MoviesExample.Domain.Entities;
{
	public class Genre : BaseAuditableEntity
	{
		[Required]
		[MaxLength(20)]
		public string? Name { get; set; }
	}
}

//Generated code by the source generator
namespace MoviesExample.Application.Genres.Commands.CreateGenre
{
    public static class CreateGenreCommandValidators
    {
        public static IRuleBuilderOptions<CreateGenreCommand, string> Name<CreateGenreCommand>(this IRuleBuilder<CreateGenreCommand, string?> ruleBuilder)
        {
            return ruleBuilder
                .NotEmpty().WithMessage("{0} is required.")
                .MaximumLength(20).WithMessage("{0} must not exceed 20 characters.");
        }
    }
}

Examples

Support

If you are having problems, please let us know by raising a new issue.

License

This project is licensed with the MIT license.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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.
  • net6.0

    • No dependencies.

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
1.0.1 336 11/28/2022 1.0.1 is deprecated because it is no longer maintained.