Swallow.Validation.Core
4.0.0
See the version list below for details.
dotnet add package Swallow.Validation.Core --version 4.0.0
NuGet\Install-Package Swallow.Validation.Core -Version 4.0.0
<PackageReference Include="Swallow.Validation.Core" Version="4.0.0" />
paket add Swallow.Validation.Core --version 4.0.0
#r "nuget: Swallow.Validation.Core, 4.0.0"
// Install Swallow.Validation.Core as a Cake Addin #addin nuget:?package=Swallow.Validation.Core&version=4.0.0 // Install Swallow.Validation.Core as a Cake Tool #tool nuget:?package=Swallow.Validation.Core&version=4.0.0
Swallow.Validation
Package | Version | Comment |
---|---|---|
Swallow.Validation.Core | Core validation library. Use this if you want to define all assertions and errors yourself. | |
Swallow.Validation | "Batteries included" version with a handful of assertions and errors. | |
Swallow.Validation.ServiceCollection | Extension for registering a ValidationContainer and its asserters in an IServiceCollection |
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.
Standout 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.
Getting started
To get started with the library, check out the validation 101 in the documentation.
If you wish to know more about the validations and what you can do with them, I suggest you just find out by digging through the code or just using the library to build some validations.
And if you feel like something is missing (or just plain broken), feel free to create an issue.
Licensing
Swallow.Validation
is licensed under the MIT license. That means you can do whatever you like with
it, as long as you give credit by including the library's license when distributing your software.
The logo (the swallow) is taken from www.freevector.com.
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 Swallow.Validation.Core:
Package | Downloads |
---|---|
Swallow.Validation
A lightweight, fluent-style validation library |
|
Swallow.Validation.ServiceCollection
A lightweight, fluent-style validation library |
GitHub repositories
This package is not used by any popular GitHub repositories.
See https://gitlab.com/phkiener/swallow.validation/-/blob/master/RELEASE_NOTES.md for release notes