Documentation will be added soon...
The MediatorChain class is a part of the MediatR.Chained library and is used to create and execute a chain of commands or requests sequentially. It provides a fluent interface for adding requests to the chain and executing them asynchronously.
You can install the MediatR.Chained library via NuGet. Run the following command in the NuGet Package Manager Console:
dotnet add package MediatR.ChainedTo use the MediatorChain class, follow these steps:
-
Create an instance of the
MediatorChainclass by passing an instance of theIMediatorinterface and a list ofMediatorChainStepobjects representing the steps in the chain. -
Use the
Addmethod to add requests to the chain. There are two overloads of theAddmethod:- The first overload takes a request object of type
IRequest<TNext>and adds it to the chain. It returns the next mediator chain with the added request. - The second overload takes a function that creates a request based on the previous result. It returns the next mediator chain with the added request.
- The first overload takes a request object of type
-
Use the
FailWhenmethod to add a condition to the chain that fails when the specified predicate returns true. This method is only available when using a mediator chain with a previous result. -
Use the
SendAsyncmethod to execute the chain of requests asynchronously and retrieve the response. There are two overloads of theSendAsyncmethod:- The first overload returns the response of type
TResponse. - The second overload returns the response as an object.
- The first overload returns the response of type
Here's an example of how to use the MediatorChain class:

You can install the MediatR.Chained.EntityFrameworkCore library via NuGet. Run the following command in the NuGet Package Manager Console:
dotnet add package MediatR.Chained.EntityFrameworkCorecoming soon...
This library is licensed under the MIT License. See the LICENSE file for more details.