Skip to main content

Posts

Showing posts with the label CQRS Pattern

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

A .Net5 Sample Using CQRS(Command Query Responsibility Segregation) And MediatR Patterns

CQRS stands for Command Query Responsibility Segregation. CQRS guides us to separate our logical implementations into 2 categories like 'Commands', 'Query'. The 'Commands' specifies the operations like creation or updating of data into the data source(database). The 'Query' specifies the operations to fetch the data. In CQRS models(Request/Response classes) are independent or owned by a single operation, which means model classes can not be shared between the different 'Commands' or different 'Queries' or between a 'Command' and 'Query'. From the diagram one thing to observe Request/Response model(optional), that's because some times we will use query parameters or return a simple scalar type in those cases we won't create models. Create .Net5 Web API: To implement the CQRS pattern let's create a sample .Net5 Web API application. Configure Entity Framework Core Database Context: For this demo, I had created