https://github.com/lefttwixwand/moderncqrs
This repository shows, how to implement CQRS architecture pattern, using Autofac and MediatR libraries.
https://github.com/lefttwixwand/moderncqrs
autofac autofac-container autofac-di cqrs csharp decorator decorator-pattern decorators dotnet mediator-pattern mediatr mediatr-library
Last synced: 6 months ago
JSON representation
This repository shows, how to implement CQRS architecture pattern, using Autofac and MediatR libraries.
- Host: GitHub
- URL: https://github.com/lefttwixwand/moderncqrs
- Owner: LeftTwixWand
- Created: 2021-11-04T10:46:07.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2025-04-06T00:17:11.000Z (6 months ago)
- Last Synced: 2025-04-06T00:23:29.745Z (6 months ago)
- Topics: autofac, autofac-container, autofac-di, cqrs, csharp, decorator, decorator-pattern, decorators, dotnet, mediator-pattern, mediatr, mediatr-library
- Language: C#
- Homepage:
- Size: 60.5 KB
- Stars: 30
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## This repository shows, how to implement CQRS architecture approach, using [Autofac](https://github.com/autofac/Autofac) and [MediatR](https://github.com/jbogard/MediatR) libraries.
The main purpose is to create a simple app with clear CQRS requests processing behavior.
This repository demonstrates how to:
- Set up the **MediatR**
- Create custom **Commands** / **Queries** and its handlers
- Add **decorators** for all types of request handlers
- Add **decorators** only for Command or Query handlers
- Use **pipelines** (**MediatR** Behaviours like request Pre Processors and Post Processors)The sample app output:

### The architecture
```mermaid
flowchart TD
%% Start with client call
Start([Client]) -->|"mediator.Send(command)"| MediatR[MediatR]
%% Simple flow through layers
MediatR --> Pipeline
subgraph Pipeline [Request Pipeline]
direction TB
PreProc[Pre-Processors Layer] --> Decorators1[Decorators Layer]
Decorators1 --> Handler[Request Handler]
Handler --> Decorators2[Decorators Layer]
Decorators2 --> PostProc[Post-Processors Layer]
end
Pipeline --> Response([Response])
%% Cross-mode optimized styling (works well in both light and dark themes)
classDef client fill:#4D7EA8,stroke:#2C4D6E,stroke-width:2px,color:white,font-weight:bold
classDef pipeline fill:#6B7FD7,stroke:#3B4AA0,stroke-width:2px,color:white
classDef layer fill:#9683EC,stroke:#644CB5,stroke-width:1px,color:white
classDef handler fill:#50B9A0,stroke:#2E6B5E,stroke-width:2px,color:white,font-weight:bold
classDef structure fill:#E6777E,stroke:#B24248,stroke-width:1px,color:white
class Start,Response client
class Pipeline,MediatR pipeline
class PreProc,Decorators1,Decorators2,PostProc layer
class Handler handler
class RequestStructure,HandlerStructure,IRequest,IIdentReq,CmdQuery,IReqHandler,ICmdHandler,IQryHandler structure
``````mermaid
flowchart TD
%% Simplified hierarchy on the side
subgraph RequestStructure [Request Hierarchy]
direction TB
IRequest[MediatR.IRequest] --> IIdentReq[IIdentifiableRequest]
IIdentReq --> CmdQuery[CommandBase/QueryBase]
end
%% Simplified handler hierarchy
subgraph HandlerStructure [Handler Hierarchy]
direction TB
IReqHandler[MediatR.IRequestHandler] --> ICmdHandler[ICommandHandler]
IReqHandler --> IQryHandler[IQueryHandler]
end
%% Cross-mode optimized styling (works well in both light and dark themes)
classDef client fill:#4D7EA8,stroke:#2C4D6E,stroke-width:2px,color:white,font-weight:bold
classDef pipeline fill:#6B7FD7,stroke:#3B4AA0,stroke-width:2px,color:white
classDef layer fill:#9683EC,stroke:#644CB5,stroke-width:1px,color:white
classDef handler fill:#50B9A0,stroke:#2E6B5E,stroke-width:2px,color:white,font-weight:bold
classDef structure fill:#E6777E,stroke:#B24248,stroke-width:1px,color:white
class Start,Response client
class Pipeline,MediatR pipeline
class PreProc,Decorators1,Decorators2,PostProc layer
class Handler handler
class RequestStructure,HandlerStructure,IRequest,IIdentReq,CmdQuery,IReqHandler,ICmdHandler,IQryHandler structure
```