Assimalign.Extensions.Validation 1.0.0-pre.1.0.4

Prefix Reserved
This is a prerelease version of Assimalign.Extensions.Validation.
dotnet add package Assimalign.Extensions.Validation --version 1.0.0-pre.1.0.4                
NuGet\Install-Package Assimalign.Extensions.Validation -Version 1.0.0-pre.1.0.4                
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="Assimalign.Extensions.Validation" Version="1.0.0-pre.1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Assimalign.Extensions.Validation --version 1.0.0-pre.1.0.4                
#r "nuget: Assimalign.Extensions.Validation, 1.0.0-pre.1.0.4"                
#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 Assimalign.Extensions.Validation as a Cake Addin
#addin nuget:?package=Assimalign.Extensions.Validation&version=1.0.0-pre.1.0.4&prerelease

// Install Assimalign.Extensions.Validation as a Cake Tool
#tool nuget:?package=Assimalign.Extensions.Validation&version=1.0.0-pre.1.0.4&prerelease                

Assimalign Extensions Validation

<br/> <br/>


Concepts

To create a cleaner implementation to fluent validation and allow for better extensibility.

The key pattern of encapsulation follows this flow:

           Validator
(encapsulates) └─> Validation Profiles 
                            └─> Validation Items
                                        └─> Validation Rules
  • Validator: The instance running the validation.
  • Validation Profile: The configurable object which describes the validation items and rules.
  • Validation Item: The item being described for validation. (This is usually the member or field of a Type)
  • Validation Rule: The rules to be applied for a specific validation item.

<br/> <br/>


Getting Started

1. Creating a Validation Profile

First create a type and define the validation rules with the built ValidationProfile.


public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime Birthday { get; set; }
}


public class PersonValidationProfile : ValidationProfile<Person>
{

    public PersonValidationProfile()
    {
        // Specify that the validation stop of first failure
        base.ValidationMode = ValidationMode.Stop;
    }


    public override void Configure(IValidationRuleDescriptor<Person> descriptor)
    {
        descriptor.RuleFor(p => p.FirstName)
            .NotEmpty()
            .MaxLength(255);

        descriptor.RuleFor(p => p.LastName)
            .NotEmpty()
            .MaxLength(255);

        descriptor.RuleFor(p => p.Birthday)
            .LessThan(DateTime.Now)
            .NotEqual(default(DateTime));
    }
}

2. Building a Validator

Build a validator by passing the the


var validator = Validator.Create(options => 
{
    // Optional configurations
    options.ThrowExceptionOnFailure = true; 

    // Required Configurations
    options.AddProfile(new PersonValidationProfile());
});

3. Running Validation

Instantiate the type and pass it through the validator


var person = new Person() 
{
    FirstName = "Chase",
    LastName = "Crawford",
    Birthday = default(DateTime)
};

var validationResults = validator.Validate(person);


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 (2)

Showing the top 2 NuGet packages that depend on Assimalign.Extensions.Validation:

Package Downloads
Assimalign.Extensions.Validation.Configurable

This library is an abstraction for implementing a configurable validator which extends off the Assimalign.Extensions.Validation library.

Assimalign.Azure.WebJobs.Extensions.Validation

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-pre.1.0.4 130 6/16/2022
1.0.0-pre.1.0.3 121 5/23/2022
1.0.0-pre.1.0 136 5/23/2022