Mediator Pattern in ASP.NET Core Applications

Send commands, fetch queries, and broadcast events using a mediator pattern for CQRS+ES

João Simões
The Startup

--

For the last few years, Command Query Responsibility Segregation (CQRS) and Event Sourcing (ES) emerged as patterns that can help implement large scale systems, with some risky complexity, by having different models to read or mutate data while also using events as a single source of truth.

Since there are already great articles explaining CQRS or ES in great depth, I’m going to focus and show how you can decouple your application layers by only knowing POCOs and a mediator instance from SimpleSoft.Mediator.

Remember that, even if you are not using CQRS or ES to its full extend, just by ensuring a logical model segregation inside the project can make your life easier in the long run, even when implementing a simple Backend for Frontend (BFF) or a minimum viable product (MVP).

Commands, Queries, Events, Handlers and Mediator

Before showing some code, lets make a simple review of some core concepts about these patterns and the library we are going to use:

  • Commands — each action intended to change the system state, by creating, updating or deleting information, should…

--

--

João Simões
The Startup

Solutions Architect trying to solve world “problems”! Creator of https://code-corner.dev