Mediator to the Rescue: Cross-Cutting Concerns with .NET Minimal APIs

Athan Bonis
6 min readJun 2, 2023

The Mediator Pattern is a common approach to decoupling the components inside your services. It simplifies the communication of complex parts of your code, and allows the easy addition of new features to your existing code base, giving you the opportunity to easily scale your system.

Just to give some historical context, while the Mediator pattern has been around from the early days of Software Engineering it was first formally introduced in the book Design Patterns: Elements of Reusable Object-Oriented Software.

Let’s be straightforward and not give more descriptions about the Mediator pattern since you can find a ton of it with a little search — or some chatting with ChatGPT (but please be careful and cross-check the information that this thing provides you — it’s not always correct :) ).

In the previous article, we saw an Introduction to .NET Minimal APIs. Today we are going to cover the next topic that I had in mind when I started talking about the Minimal APIs.

How the use of the Mediator pattern in your Minimal APIs, can help you write clean code and allows you to incorporate Cross-Cutting Concerns.

Let’s start!

We will use as a base implementation the OrderService we created in the previous…

--

--

Athan Bonis

Ηighly motivated Software Engineer. I have a strong passion for problem-solving and learning new technologies, targeting to produce clean and structured code.