Assimalign.Extensions.Validation
1.0.0-pre.1.0
Prefix Reserved
See the version list below for details.
dotnet add package Assimalign.Extensions.Validation --version 1.0.0-pre.1.0
NuGet\Install-Package Assimalign.Extensions.Validation -Version 1.0.0-pre.1.0
<PackageReference Include="Assimalign.Extensions.Validation" Version="1.0.0-pre.1.0" />
paket add Assimalign.Extensions.Validation --version 1.0.0-pre.1.0
#r "nuget: Assimalign.Extensions.Validation, 1.0.0-pre.1.0"
// Install Assimalign.Extensions.Validation as a Cake Addin #addin nuget:?package=Assimalign.Extensions.Validation&version=1.0.0-pre.1.0&prerelease // Install Assimalign.Extensions.Validation as a Cake Tool #tool nuget:?package=Assimalign.Extensions.Validation&version=1.0.0-pre.1.0&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 | Versions 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. |
-
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 | 145 | 6/16/2022 |
1.0.0-pre.1.0.3 | 130 | 5/23/2022 |
1.0.0-pre.1.0 | 145 | 5/23/2022 |