Skip to main content


Showing posts with the label ASP.NET Core Web API

AutoMapper In Asp.Net Core Applications

AutoMapper: Automapper is an object-to-object mapper. Object to object mapping works by transforming an input object of one type into an output object of a different type. Manually mapping one object property value to another object property value leads to more lines of code, so all this dirty work can be avoided by using the Automapper. As long as all properties names are the same for 2 different objects that need to map, almost zero configuration is needed to map them.  When To Use AutoMapper?: In any kind of architecture, it is always advised to not expose the 'Entity'(Table classes) directly. So we will create replica classes for 'Entity' we called them as 'DTO'(Data Transfer Object) or 'VM'(View Models). So this is the real-time best case to use Automapper for mapping 'Entity'(Table classes) data to DTO or VM's. Create A Sample Dotnet5 Web API Project: In this demo, we are going to understand the different mapping techniques that are

A Demo On .Net5 Web API Pagination Using Dapper ORM

In this article, we are going to implement a sample demo on pagination in .Net5 Web API application using Dapper ORM for database communication. Create A Sample Table: To accomplish our demo let's create a sample table. CREATE TABLE [dbo].[Todo]( [Id] [int] IDENTITY(1,1) NOT NULL, [ItemName] [varchar](max) NULL, [IsCompleted] [bit] NOT NULL CONSTRAINT Pk_Todo PRIMARY KEY (Id) ) Create A .Net5 Web API Application: Let's create a .Net5 Web API application to implement our pagination. Specify the project name and solution name Select target framework a .Net5 Create Table Model and Pagination Response Model: Now we need to create to models like 'Todo'(Table Class) and 'PagingResponseModel'(Class that  used as API response model which contains all pagination properties). So let's add a new folder like 'Models' and our 2 classes inside of it. Models/Todo.cs: namespace Dot5.API.Dapper.Pagging.Models { public class Todo { public

.Net5 Web API Redis Cache Using StackExchange.Redis.Extensions.AspNetCore Library

In this article, we are going to explore the integration of Redis cache in .Net5 Web API application using the 'StackExchange.Redis.Exntensions' library. Note:- Microsoft has introduced an 'IDistributedCache' interface in dotnet core which supports different cache stores like In-Memory, Redis, NCache, etc. It is simple and easy to work with  'IDistributedCache', for the Redis store with limited features but if we want more features of the Redis store we can choose to use 'StackExchange.Redis.Extensions'.  Click here for Redis Cache Integration Using IDistributedCache Interface . Overview On StackExchange.Redis.Extnesions Library: The 'StackExchange.Redis.Extension' library extended from the main library 'StackExchange.Redis'. Some of the key features of this library like: Default serialization and deserialization. Easy to save and fetch complex objects. Search key. Multiple Database Access Setup Redis Docker Instance: For this sampl

Redis Cache Implementation In .NetCore Web API Using Distributed Caching Technique(Redis Docker Instance)

Redis Cache: Redis is an open-source in-memory data structure store, used as a database, cache. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, etc. Setup Redis Docker Instance: For this sample to use Redis instance locally we will use Docker. If you don't have any prior knowledge of docker, not a problem just follow the steps below.  Click here for a video session on Redis docker setup Note: Skip this section if you already have redis direct instance or azure or any cloud provider that have redis Step1: Download docker into our local system "" . Docker was available for all desktop operating systems. Step2: After downloading the docker installer, then install it. Now to run any docker containers(eg: Redis, MongoDB, PostgreSQL, etc) this docker instance we just installed should be active(should be running). Step3: Now we need to pull the docker Redis image from the docker hub "http

A Sample On .Net Core Web API Using Dapper

Overview On Dapper Object-Relational Mapping: Dapper is an Object-Relational Mapping framework for .Net applications. It is a mapping model between the database and .Net objects. The Dapper provides all query and command execution methods as extension methods under the 'System.Data.IDbConnection' interface. The Dapper works as a similar ADO.Net but with much more model mapping support. The Dapper key features are like: High performance in query execution Multiple query execution support An easy model mapping between the .Net Object and database result. Create A Sample .Net Core Web API Application: Let's understand the Dapper ORM query and commands execution steps by writing some sample code, so let's get started by creating a .Net Core Web API application. The IDE's for development can be chosen by personal preference but the most recommended IDE's are Visual Studio 2019 and  Visual Studio Code . SQL Table Schema: In this article we are going to work on 'T