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.Chained
To use the MediatorChain
class, follow these steps:
-
Create an instance of the
MediatorChain
class by passing an instance of theIMediator
interface and a list ofMediatorChainStep
objects representing the steps in the chain. -
Use the
Add
method to add requests to the chain. There are two overloads of theAdd
method:- 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
FailWhen
method 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
SendAsync
method to execute the chain of requests asynchronously and retrieve the response. There are two overloads of theSendAsync
method:- 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.EntityFrameworkCore
coming soon...
This library is licensed under the MIT License. See the LICENSE file for more details.