Skip to content

A straightforward Asp.Net Minimal API that demonstrates the implementation of CQRS (Command Query Responsibility Segregation) without requiring any library.

Notifications You must be signed in to change notification settings

MehediMayall/CQRS-without-MediatR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CQRS-without-MediatR

A straightforward Asp.Net Minimal API that demonstrates the implementation of CQRS (Command Query Responsibility Segregation) without requiring any library. The aim of this project is to learn how to physically divide classes into two distinct responsibilities, in order to achieve scalability, maintainability, performance and adapt to two mindsets. It is highly adaptable in navigating complex domains, allowing for independent customization of the data structure for read and write operations.

CQRS Architecture

Folder Structure

.
├── MinimalApiCqrs
│   ├── Database
│   │   └── InMemoryDatabase.cs
│   ├── EndPoints
│   │   └── Movies.cs
│   ├── Entities
│   │   ├── EntityBase.cs
│   │   └── Movie.cs
│   ├── MinimalApiCqrs.csproj
│   ├── MinimalApiCqrs.http
│   ├── Program.cs
│   ├── Properties
│   │   └── launchSettings.json
│   ├── Repositoris
│   │   ├── Abstractions
│   │   │   ├── IMovieReadRepository.cs
│   │   │   ├── IMovieWriteRepository.cs
│   │   │   ├── IReadRepository.cs
│   │   │   └── IWriteRepository.cs
│   │   ├── MovieReadRepository.cs
│   │   └── MovieWriteRepository.cs
│   ├── appsettings.Development.json
│   ├── appsettings.json
│   ├── handlers
│   │   ├── command
│   │   │   ├── AddBookCommand.cs
│   │   │   ├── DeleteBookCommand.cs
│   │   │   └── UpdateBookCommand.cs
│   │   └── queries
│   │       ├── GetBookByIdQuery.cs
│   │       └── GetBookQuery.cs
└── MinimalApiCqrs.sln

ReadRepository has only one responsibility that is all of its methods are used to read data from the database. It is used to transfer data from database to the application as efficient as possible without changing its state

WriteRepository has only one responsibility that is all of its methods are used to write data to the database. It is used to transfer data from application to the database in more generic ways.

Dependency Flow

Dependency Flow

Loose Coupling Through Mediator Pattern

Here is an example of how an update operation functions in a loosely coupled manner. In the UpdateMovieCommandHandler class, we have two interactions with the database using two different objects. First, we have to retrieve the last state of that movie from the database. Second, we have to replace the old state with the new one and save the latest state (Movie) in the database. This has to be done in a loosely coupled way. Loose Coupling

About

A straightforward Asp.Net Minimal API that demonstrates the implementation of CQRS (Command Query Responsibility Segregation) without requiring any library.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages