Microservices is a great architecture for modern applications that need to be scalable and resilient to failures in order to be able to support millions of transactions.
In order to understand why the microservice architecture can be better than monolithic, it is needed to understand the drawbacks of monolithic applications.
Some time ago I got a new requirement. When analyzing the requirement I realized that I would need some design patterns.
When I was first introduced to design patterns I got some trouble understanding them because of the lack of real-life scenarios.
This post contains the usage of the Factory and Strategy pattern in a real-life scenario to create a clean and maintainable code by following the SOLID principles in a real-life scenario.
As a note, it is important to denote that the application follows the CQRS architectural pattern. (You will see the usage of Mediatr library along with some Commands, Queries, and Handlers)
When implementing CQRS using MediatR it is possible to implement pipelines behaviors.
These pipelines allow to catch all commands and queries and gives the ability to execute some logic before and after the Commands and Queries Handlers are executed.
The Validation pipeline behavior
One of the many pipelines that can be added is the validation pipeline behavior which adds logic to validate the properties in the Commands and Queries, resulting in that only valid requests will be passed to the Commands and Queries Handlers.