Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Guides & Recipes — Mediator

Practical patterns for writing zero-allocation mediator behaviors and isolated unit tests.

using System.Threading;
using System.Threading.Tasks;
using EricksonLopez.Mediator;
namespace Example.MediatorRecipes;
public sealed class TimingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
{
public async ValueTask<TResponse> Handle<TNext>(
TRequest request,
TNext next,
CancellationToken cancellationToken)
where TNext : struct, INext<TResponse>
{
return await next.InvokeAsync();
}
}

Use EricksonLopez.Mediator.Testing.FakeMediator in presentation/application unit tests to stub responses (SetupCommand, SetupQuery) and assert exact dispatch counts (ShouldHaveReceived<T>(), ReceivedCount<T>()).