Skip to main content

Posts

Why We Have To Unsubscribe An Observable In An Angular Application?

Unsubscribe An Observable: In Angular applications, it's always recommended to unsubscribe the observables to gain benefits like: Avoids Memory Leaks Aborting HTTP requests to avoid unwanted calls. So in this demo, we will understand the case studies to unsubscribe an observable. Memory Leaks: Now let's implement observables code with memory leaks. So first let's create a service like 'test.service.ts' inside of initialize the 'BehaviourSubject' as below. services/test.service.ts: import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @Injectable({ providedIn: 'root', }) export class TestService { randNumberSub: BehaviorSubject<number> = new BehaviorSubject<number>( Math.random() ); } (Line: 8-10) Initialized 'BehaviorSubject' of type 'number'. Now let's create components like 'sample1.component.ts' and 'sample2.component.ts' these will c

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