Skip to main content

Posts

Usage Of CancellationToken In Asp.Net Core Applications

When To Use CancellationToken?: In a web application request abortion or orphan, requests are quite common. On users disconnected by network interruption or navigating between multiple pages before proper response or closing of the browser, tabs make the request aborted or orphan. An orphan request can't deliver a response to the client, but it will execute all steps(like database calls, HTTP calls, etc) at the server. Complete execution of an orphan request at the server might not be a problem generally if at all requests need to work on time taking a job at the server in those cases might be nice to terminate the execution immediately. So CancellationToken can be used to terminate a request execution at the server immediately once the request is aborted or orphan. Here we are going to see some sample code snippets about implementing a CancellationToken for Entity FrameworkCore, Dapper ORM, and HttpClient calls in Asp.NetCore MVC application. Note: The sample codes I will show in

Blazor WebAssembly File Upload Using MudBlazor UI Components

In this article, we are going to implement a Blazor WebAssembly application file upload using MudBlazor UI components. Create A Sample Blazor WebAssembly Application: Let's create a sample Blazor WebAssembly application to accomplish our demo on file uploading. Initial MudBlazor Setup: Install the 'MudBlazor' library package. Add Mudblazor namespace into the '_Imports.razor'. _Imports.razor: @using MudBlazor Add the below CSS files inside of the head tag in 'index.html'. wwwroot/index.html: <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" /> <link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" /> Now comment the 'bootstrap.min.css' and '{your_applicationname}.styles.css' links in the head tag. Add MudBlazor javascript file in 'index.html' just above the closing body tag. wwwroot/index.html: <script

A Demo On Hot Chocolate GraphQL Integration In Asp.Net Core Application Using Dapper Micro ORM

In this article, we are going to implement a GraphQL Endpoint by using Pure Code First Techniques in the Asp.Net Core application, and database communication will be accomplished by using Dapper Micro ORM. GraphQL: GraphQL is an open-source data query and manipulation and language for APIs. It is a query language for your API and a server-side runtime for executing queries by using a type system you define for your data. GraphQL can be integrated into any framework like .Net, Java, NestJS, etc and it isn't tied to any specific database or storage engine and is instead backed by your existing code and data. GraphQL main operations are: Query (fetching data) Mutation (saving or updating data) Hot Chocolate GraphQL: Hot Chocolate is the wrapper library of the original.Net GraphQL library. Hot Chocolate takes the complexity away from building a fully-fledged GraphQL server. The hot Chocolate library provides 3 different techniques: Schema First Code First Pure Code First Schema Fi

NestJS Application Using CQRS Design Pattern

In this article, we will implement the CQRS Design Pattern in the NestJS sample application. CQRS: CQRS stands for Command Query Responsibility Segregation. CQRS guides us to separate our logical implementation into 2 categories like 'Command', 'Query'. The 'Commands' specifies the operation like creation or updating of data into the data source(database). The 'Query' specifies the operations to fetch the data. PostgreSQL Database: For this demo, I'm using the free open-source PostgreSQL database. Here I'm going to use the PostgreSQL docker image because it is easy and fast to set up and configure.  Click here to getting started with PostgreSQL docker . Run the below command to create an example table for a demo like 'Person'. CREATE TABLE Person( Id SERIAL PRIMARY KEY NOT NULL, Name Text NULL, Age INT NULL ) Create A NestJS Application: Let's begin our demo by creating a sample NestJS application. Command To Install NestJS C

A Demo On Request Logging Using MediatR IPipelineBehavior In Asp.Net Core Application

Click here  for step by step implementation of the CQRS MediatR design pattern. In this article, we are going to do request logging into an Asp.Net application Core application build on the CQRS MediatR design pattern. The application request logging helps to track the time taken per request. The MediatR provides a pipeline interface that is 'IPipelineBehavior' that helps to implement our logging logic. IPipelineBehavior: The 'IPipelineBehavior' exactly works like Asp.Net Core middleware, but its starting execution and ending execution happens within the 'IMediator'. So the 'IMediator.send()' is usually used to invoke the 'Query' or 'Command' handlers. So if we implement 'IPipelineBehavior' then begin logic inside of its start executes then invokes 'Query' or 'Command' handlers, later again go through 'IPipelineBehavior' and executes the end logic. Create A .Net5 Web API Sample Application: In this