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]

Api Versioning in Dotnet Core

Api versioning in .net core

Photo by Jan Loyde Cabrera at medium.com

When you are going to do some breaking changes in your apis, it is better to create a new version for that, so that user don’t freaked out. They still can use the older APIs and get ready for new changes. There are various way to create a versions of your APIs like

  1. Query string
  2. URL
  3. HTTP header

If you prefer video version then you can checkout this video with same content.

[Read More]

Angular Autocomlete With Ng Select

Angular Autocomlete With Ng Select

There are various packages available for implementing autocomplete in angular and we are going to use the simplest one (ng-select).

Let’s finish talking and need to start write code. Let’s install ng-select package from command line

npm install --save @ng-select/ng-select

[Read More]

Angular pagination with infinite scroll (using ngx-infite-scroll)

angular infinite scroll

Photo by Ajda ATZ on Unsplash

Sometimes we get a condition where you don’t want to display all the data at once. Initially we display some data, and when we scroll down ,we loads more data. This kind of behaviour you can see in youtube, instagram or facebook. You might even spend much time of your day on just scrolling down. So we are gonna learn how to do that.

[Read More]

Write dapper effectively with generic methods

Dapper tutorial with dotnet core

Dapper is a micro ORM for database connectivity in dotnet and it’s been around for quite a while. It is loved by most of the developers because of its simplicity and performance.

Why dapper?

With the help of dapper you can quickly access the data without writing too much code. It performs very well because we directly write queries and executes them. Developers who loves to work with queries and for the projects, where performance really matters where you wants to write very optimized queries, dapper can be the good choice.

[Read More]

Serilog in .NET

serilog-in-dotnet

In your development journey you have faced so many runtime exceptions. You have handled that with try catch block. But in the runtime you never know where that error has happened and you have to trace that whole section with putting breakpoints. Sometime you have thought that I wish.. I would get notified whenever that exception occur. Then the logging frameworks comes in the play.

Although .net core comes with its own logging mechanism but it have very limited options for logging. With 3rd party logging framework or 3rd party logging library you have multiple options, like you can log into files, console, database and so on.

[Read More]