Swallow.Validation.ServiceCollection
8.0.0
dotnet add package Swallow.Validation.ServiceCollection --version 8.0.0
NuGet\Install-Package Swallow.Validation.ServiceCollection -Version 8.0.0
<PackageReference Include="Swallow.Validation.ServiceCollection" Version="8.0.0" />
paket add Swallow.Validation.ServiceCollection --version 8.0.0
#r "nuget: Swallow.Validation.ServiceCollection, 8.0.0"
// Install Swallow.Validation.ServiceCollection as a Cake Addin #addin nuget:?package=Swallow.Validation.ServiceCollection&version=8.0.0 // Install Swallow.Validation.ServiceCollection as a Cake Tool #tool nuget:?package=Swallow.Validation.ServiceCollection&version=8.0.0
Swallow.Validation
Swallow.Validation
is a lightweight, fluent-style validation library for C#. But what does that mean? It means minimal dependencies (none, actually)
and great developer experience. If you've seen Fluent Assertions, you might find some similarities.
Usage
Features
Swallow.Validation
does not require a separate class to contain the validation logic - you can just drop it right into your code without problems.
This allows you to enforce invariants rather than validate the state of entities; instead of constructing a person and checking whether it is correct,
you can make sure that no person created can ever be in an invalid state - without needing to remember calling
new PersonValidator().Validate(myPerson)
.
The library is also "natively extensible", meaning you can create custom validation rules that perfectly blend in together with the predefined validation rules and the fluent style. You can create rules matched for your problem domain and use your own ubiquitous language. With the fluent style of the library, you can formulate validation rules directly in your domain language.
Validator.Check()
.That(Country).IsValidIsoCode()
.That(DeliveryDate).IsAfter(DateTime.UtcNow)
.That(Items).IsNotNull().IsNotEmpty()
.ElseThrow()
Additionally, the validation errors are strongly typed. Instead of throwing around strings everywhere, you have meaningful errors containing properties to describe the problem in an exact manner. You also need not worry about wording your error messages when doing your validation. You can also easily test validation logic this way; instead of comparing strings, you can just check if the error is of the correct type. You can even localize the error messages if you'd like; that way, the validation errors can even be given directly to the user.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Swallow.Validation (>= 8.0.0)
- Swallow.Validation.Core (>= 8.0.0)
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 |
---|---|---|
8.0.0 | 78 | 11/25/2024 |
7.0.0 | 135 | 1/20/2024 |
6.0.1 | 211 | 7/2/2023 |
6.0.0 | 289 | 1/22/2023 |
5.0.1 | 358 | 11/13/2022 |
5.0.0 | 431 | 7/17/2022 |
4.2.0 | 445 | 6/20/2022 |
4.1.1 | 436 | 5/29/2022 |
4.1.0 | 466 | 2/13/2022 |
4.0.0 | 426 | 2/13/2022 |
3.1.0 | 361 | 6/5/2021 |
3.0.0 | 299 | 5/20/2021 |
2.0.0 | 424 | 3/27/2021 |
1.2.0 | 412 | 11/23/2020 |
1.1.0 | 560 | 7/25/2020 |
1.0.0 | 491 | 6/21/2020 |