Programming Tips 💡
51.5K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips 💡
Articles 📕
Resources 👟
Design Patterns 💎
Software Principles ✅

🇳🇱 Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
Fluent Validation ⚠

A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. 🚫

NuGet Packages :
Install-Package FluentValidation


For ASP.NET MVC integration :
Install-Package FluentValidation.MVC5


For ASP.NET Core :
Install-Package FluentValidation.AspNetCore


🔹🔞🔹🔞

Example :

public class PersonValidator : AbstractValidator<Person>
{
public PersonValidator()
{
RuleFor(x => x.ID).NotEmpty();

RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.MinimumLength(5)
.WithMessage("Minimum length for {PropertyName} is {MinLength} !");

RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.MinimumLength(5)
.WithMessage("Minimum length for {PropertyName} is {MinLength} !");

RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.EmailAddress()
.WithMessage("{PropertyName} is not valid !");
}
}


🔹🔞🔹🔞

https://t.me/pgimg/78

[ Github ] : http://bit.do/flval

〰〰〰〰〰〰
#CSharp #AspMvc #Validation
@ProgrammingTip
ASP.NET Core 2 – Global Model Validation ⚠

We use a lot of repetitive code in our actions. ♻

Inside of our controller actions we usually check if the model is valid by using ModelState property available on MVC’s base controller class :

if (!ModelState.IsValid)  
return BadRequest(ModelState);


The bad thing about is that we repeat this piece of code throughout a lot of our actions. ❌

How we can make it better❓

This article shows you how to validate ModelState with a global filter. 💎

https://t.me/pgimg/112

[ Article ] : bit.do/mval

〰〰〰〰〰〰
#AspMvc #Core #Validation
@ProgrammingTip
Superstruct 🔥

A simple and composable way to validate data in Javascript. ✹

Superstruct makes it easy to define interfaces and then validate JavaScript data against them. ⚠

Its type annotation API was inspired by Typescript, Flow, Go, and GraphQL, giving it a familiar and easy to understand API. 🧠

But Superstruct is designed for validating data at runtime, so it throws (or returns) detailed runtime errors for you or your end users. 👥

This is especially useful in situations like accepting arbitrary input in a REST or GraphQL API, but it can even be used to validate internal data structures at runtime when needed. ✅


[ Github ] : kutt.it/SprStr

〰〰〰〰〰〰
#JavaScript #Validation
@ProgrammingTip