Fluent Validation in Dotnet Core

fluent validation in asp.net core

Fluent validation

Fluent validation is an open source library for validating the models, which is free as of I am writing this article.

📢 📝 Last Updated: 25-March-2025

Why fluent validation?

If you already have used data annotation for validation, then you must be aware of the validation in .NET. So you might be thinking why do we need a fluent validation then.

Fluent validation helps you to separate validation logic from your models. That makes your code clean. If you have complex validation logic, then you want to define it separately rather than making your model unreadable.

[Read More]

Uploading Images in Blazor Server

upload files in blazor server

In this blog post we are going to learn how to upload files in the blazor server application. I am going to upload images in this tutorial but you can upload any file (i have created reusable code).

đź’»Source Code: https://github.com/rd003/BlazorFile/

High level overview

We will upload images to a folder of a local machine ( on a production you have to use cloud storage) with a unique name (e.g. sd$3abccc3$1.png ), that name is going to save in database.

[Read More]

Easiest Way to Handle Csv Files in Csharp

how to read and write to csv files in c#

In this tutorial we will se how to read and write data to csv file. It is pretty much easy if you have some external library for that. We are definitely going to use a library and that will be CsvHelper.

You can also check the video version of this tutorial.

First and foremost, create a c# console application in .net core. After that we need to install a nuget package, which is**CsvHelper**

[Read More]

Multiple Ways to Find Duplicates in Csharp Array

find duplicates in c# array

In C#, we can use various approaches to find duplicate elements in array. Each have pros and cons. We will use 3 approaches in this article.

  1. Using a HashSet
  2. Using a Dictionary
  3. Using LINQ

Lets take this array as an example, from this array we will extract distinct numbers and duplicate numbers.

int[] numbers = { 4,7, 2, 3, 4, 5, 3, 6, 7, 8,1, 8 };

We will use this array in all three approaches. So let’s understand one by one.

[Read More]

C# Dictionary and Its Use Cases

Use cases of c# dictionary

What is dictionary?

Dictionary is a collection, that store the value in the form of key value pair. It allows you to quick access of value using the key. This data structure is widely used in programming because of its fast look-up time, which makes it ideal for applications that require quick data retrieval

👉 You can not add duplicate key in dictionary

Creating a dictionary:

[Read More]

Catch Exception Globally in Dotnet Core Apis

Catch Exception Globally in Dotnet Core Apis

There are to ways of catching exception in .net core, one is using try/catch and other one is catching them globally. Although there is nothing wrong with try/catch blog, it is an elegant way of exception handling. Although you can also catch exceptions globally, If you want to log errors in one place. There are various approaches to achieve this, but we will create the custom middleware to achieve it.

[Read More]

Output Caching With Dotnet 7

Output Caching middleware has introduced in .net 7 , that is used to apply caching in your application. It can be used in any .net core application like Minimal API, Web API with controllers, MVC, and Razor Page. But I am using controller APIs in this project.

What is Caching?

Caching is a process of temporarily storing frequently accessed data or resources in a faster and closer location to the user or application, with the goal of reducing the time and resources needed to retrieve that data from its original source. By keeping a copy of the data nearby, caching enables quicker access and improves the overall performance and responsiveness of applications.

[Read More]

JWT Authentication and Role Based Authorization in Dotnet Core

JWT Authentication in dotnet core

JWT

According to jwt.io JSON Web Tokens are an open, industry standard RFC7519 method for representing claims securely between two parties.

When we create REST APIs, then we don’t want that any one can access those apis. REST APIs, will only be accessed by the authenticated user. We authenticate our user with the help of jwt.

How jwt works?

First, we give an authentication endpoint to user, where he/she puts credential, in return we give a jwt token to user which have an expiry date. To consume any protected resource, user need to pass jwt token on authorization header.

[Read More]

Create Sln File With Multiple Projects

Create Sln File With Multiple Projects

In this article we will learn how to create a .net core project with a Solution (sln file) that contains multiple projects. I know most you guys use visual studio for c# related stuff, but it would be benificial for person who likes to switch with vs code ocassionally, like me or who use linux and forced to use .net cli. Although if you are a new developer and have windows operating system, I will recommend visual studio, because it is the best possible IDE for c# development.

[Read More]

Ngrx Entity and Effects

ngrx entity and effects

NGRX Entity gives you an efficient and quick way to deal with ngrx store related operations, such as read, write, update, delete. You can focus on productivity, rather than creating and modifeng complex state everytime. It can be very helpful when you are dealing with complex state and handling with http services at the same time.

What is ngrx ?

Ngrx is a state management library, that stores the state globally. Lets understand some of its components.

[Read More]