Skip to content

GabrieleTronchin/MediatRPipelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Experimenting With MediatR Pipelines

This repository is a playground project used to experiment with MediatR features, particularly pipelines.

It also serves as the code base for the following articles:

Introduction to MediatR

MediatR, available as a NuGet package for .NET, embodies the mediator design pattern, a strategy aimed at decoupling communication between objects.

For a comprehensive understanding of this pattern, you can refer to the following resource: Refactoring Guru - Mediator Design Pattern.

A well-established implementation of this pattern for .NET is MediatR, whose official GitHub project can be found here.

Fundamentals of MediatR

In essence, MediatR operates across three primary modes:

  • Request: Involves a single receiver with a service response.
  • Notification: Engages multiple receivers without a service response.
  • StreamRequest: Utilizes a single receiver for stream operations with a service response.

For the scope of this project, our focus is primarily on the Request behavior, particularly on exploring MediatR Pipelines.

MediatR Pipelines

Within the mediator request flow, there exists a clear distinction between a publisher and a subscriber. By leveraging MediatR pipelines, we can effectively intercept this flow and introduce customized logic into the process.

MediatR Pipeline Use Cases

The use cases of MediatR pipelines are numerous, and they could include:

  • Logging: Use pipelines to log relevant information about requests, responses, or execution time.
  • Caching: Implementing a caching pipeline alongside requests can minimize database access, especially if you are using MediatR requests to retrieve information.
  • Request Validation: Integrating logic for validating input data before request execution ensures that only valid data is processed.
  • Unit of Work Pattern: Utilizing a pipeline to manage the unit of work facilitates transaction handling and rollback operations in a centralized manner.

Testing the Application

When starting the application, the Swagger page will appear:

Swagger Page

About

Experimenting With MediatR Pipelines

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages