Performance is king (well, after accuracy) in APIs. Sending a request to the Database only to discover that the request is invalid is a waste of resources. Thus, we want to validate the request as soon as it hits the endpoint.
FluentValidation is a great tool for creating validators. It installs as a NuGet package. Also grab the version for ASP.Net.
To get going, add a using statement.
Using FluentValidation
Next, create a class that derives from AbstractValidator.
public class CarNotDeletedValidator : AbstractValidator<Car>
This example uses the Car class from my forthcoming book Creating .NET APIs with C#.
Put your validation rules in the constructor. Each rule is created by using the keyword RuleFor and a lambda expression that indicates which property you want to validate and the validation rule.
using Cars.Data.DTOs;
using FluentValidation;
namespace Cars.Validators
{
public class CarNotDeletedValidator : AbstractValidator<CarDto>
{
public CarNotDeletedValidator()
{
RuleFor(x => x.Is_Deleted).Equal("0");
}
}
}
The Equal operator is one of many that you can find at the FluentValidation documentation page: https://docs.fluentvalidation.net/en/latest/built-in-validators.html.
We’ll test the data and then either compare it to what is valid and return an error if appropriate, or, more commonly, we’ll throw an exception if the data fails validation.
Assuming that it passes validation we can continue to the Database. If however it fails, we can return a meaningful error to the sender.




















Предлагаем вашему вниманию интересную справочную статью, в которой собраны ключевые моменты и нюансы по актуальным вопросам. Эта информация будет полезна как для профессионалов, так и для тех, кто только начинает изучать тему. Узнайте ответы на важные вопросы и расширьте свои знания!
Детальнее – https://vivod-iz-zapoya-2.ru/
Je höher Ihr Level, desto mehr Vorteile erhalten Sie – darunter Cashback,
exklusive Boni, persönliche Betreuung und Sonderaktionen. Dragon Casino verfügt über mehr als 3.000
Spiele, darunter Slots, Live-Casino, Tischspiele, Megaways, Crash Games und Sportwetten. Die
Plattform ermöglicht das Setzen von Einzahlungslimits, Sitzungszeitbegrenzungen und
bietet Selbstausschlussoptionen von 24 Stunden bis zu 6 Monaten.
Der finale Willkommensbonus bietet 225% bis zu 2250 EUR
zusammen mit 200 Freispielen. Dragon Money Casino wirbt häufig mit Willkommensboni, Turnieren und
Cashback-Aktionen, vor allem für neue Nutzer und Vielspieler.
Dragon Money ist eine Online-Glücksspielplattform,
die eine breite Palette an Spieloptionen bietet,
darunter Spielautomaten, Tischspiele, Live-Casino und Sportwetten. Die zweite Einzahlung wird mit einem 150% Bonus bis zu 300 EUR und 50
Freispielen belohnt. Neue Spieler erhalten einen 100%
Bonus bis zu 50 EUR sowie 25 Freispiele bei einer Mindesteinzahlung von 10 EUR.
References:
https://online-spielhallen.de/vinyl-casino-login-ihr-zugang-zur-spielwelt/
Admiring the commitment you put into your blog and detailed information you present. It’s awesome to come across a blog every once in a while that isn’t the same unwanted rehashed material. Excellent read! I’ve saved your site and I’m including your RSS feeds to my Google account.
Today, with all the fast life-style that everyone leads, credit cards have a huge demand throughout the market. Persons from every arena are using credit card and people who aren’t using the card have lined up to apply for one. Thanks for giving your ideas in credit cards.