![]() |
VOOZH | about |
dotnet add package Workleap.Extensions.MediatR --version 1.5.9
NuGet\Install-Package Workleap.Extensions.MediatR -Version 1.5.9
<PackageReference Include="Workleap.Extensions.MediatR" Version="1.5.9" />
<PackageVersion Include="Workleap.Extensions.MediatR" Version="1.5.9" />Directory.Packages.props
<PackageReference Include="Workleap.Extensions.MediatR" />Project file
paket add Workleap.Extensions.MediatR --version 1.5.9
#r "nuget: Workleap.Extensions.MediatR, 1.5.9"
#:package Workleap.Extensions.MediatR@1.5.9
#addin nuget:?package=Workleap.Extensions.MediatR&version=1.5.9Install as a Cake Addin
#tool nuget:?package=Workleap.Extensions.MediatR&version=1.5.9Install as a Cake Tool
This library ensures that MediatR is registered in the dependency injection container as a singleton and also adds several features:
Debug log levelUse the AddMediator(params Assembly[] assemblies) extension method on your dependency injection services (IServiceCollection) to automatically register all the MediatR request handlers from a given assembly.
builder.Services.AddMediator(typeof(Program).Assembly /*, [more assemblies...] */);
If you use Application Insights and want to instrument your handlers, you can install the dedicated NuGet package:
builder.Services.AddMediator(typeof(Program).Assembly).AddApplicationInsights();
There are multiple method overloads of AddMediator. For instance, you can override MediatR configuration using this overload that accepts a Action<MediatRServiceConfiguration>:
builder.Services.AddMediator(
cfg => cfg.NotificationPublisher = new TaskWhenAllPublisher(),
typeof(Program).Assembly);
This library automatically handles MediatR license configuration. The license key can be provided through:
MEDIATR_LICENSE_KEY environment variableMEDIATR_LICENSE_KEY key to your configuration (e.g., appsettings.json, user secrets, etc.)# Set environment variable
export MEDIATR_LICENSE_KEY="your-license-key-here"
{
"MEDIATR_LICENSE_KEY": "your-license-key-here"
}
You can also set the license key manually using the configuration overload:
builder.Services.AddMediator(
cfg => cfg.LicenseKey = "your-license-key-here",
typeof(Program).Assembly);
// CQRS naming conventions are suggested by a Roslyn analyzer, but it can be disabled
public sealed record SayHelloCommand([property: Required] string To) : IRequest;
public sealed class SayHelloCommandHandler : IRequestHandler<SayHelloCommand>
{
public Task Handle(SayHelloCommand command, CancellationToken cancellationToken)
{
Console.WriteLine($"Hello {command.To}!");
return Task.CompletedTask;
}
}
// [...] Retrieve an instance of IMediator or ISender
var mediator = serviceProvider.GetRequiredService<IMediator>();
// - We use the preferred Async-suffixed extension method to put emphasis on the asynchronous aspect of MediatR
// - A Roslyn analyzer suggests to specify a cancellation token, which is most of the time forgotten by developers
await mediator.SendAsync(new SayHelloCommand("world"), CancellationToken.None);
// This throws RequestValidationException because 'SayHelloCommand.To' is marked as required
await mediator.SendAsync(new SayHelloCommand(null!), CancellationToken.None);
| Rule ID | Category | Severity | Description |
|---|---|---|---|
| GMDTR01 | Naming | Warning | Name should end with 'Command' or 'Query' |
| GMDTR02 | Naming | Warning | Name should end with 'CommandHandler' or 'QueryHandler' |
| GMDTR03 | Naming | Warning | Name should end with 'StreamQuery' |
| GMDTR04 | Naming | Warning | Name should end with 'StreamQueryHandler' |
| GMDTR05 | Naming | Warning | Name should end with 'Notification' or 'Event' |
| GMDTR06 | Naming | Warning | Name should end with 'NotificationHandler' or 'EventHandler' |
| GMDTR07 | Design | Warning | Use generic method instead |
| GMDTR08 | Design | Warning | Provide a cancellation token |
| GMDTR09 | Design | Warning | Handlers should not call other handlers |
| GMDTR10 | Design | Warning | Handlers should not be public |
| GMDTR11 | Design | Warning | Use 'AddMediator' extension method instead of 'AddMediatR' |
| GMDTR12 | Design | Warning | Use method ending with 'Async' instead |
| GMDTR13 | Naming | Warning | Name should end with 'Handler' |
In order to change the severity of one of these diagnostic rules, use a .editorconfig file, for instance:
[*.cs]
dotnet_diagnostic.GMDTR01.severity = none
To learn more about how to configure or suppress code analysis warnings, read this documentation.
The project can be built by running Build.ps1. It uses Microsoft.CodeAnalysis.PublicApiAnalyzers to help detect public API breaking changes. Use the built-in roslyn analyzer to ensure that public APIs are declared in PublicAPI.Shipped.txt, and obsolete public APIs in PublicAPI.Unshipped.txt.
A new preview NuGet package is automatically published on any new commit on the main branch. This means that by completing a pull request, you automatically get a new NuGet package.
When you are ready to officially release a stable NuGet package by following the SemVer guidelines, simply manually create a tag with the format x.y.z. This will automatically create and publish a NuGet package for this version.
Copyright © 2023, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/workleap/gsoft-license/blob/master/LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 1 NuGet packages that depend on Workleap.Extensions.MediatR:
| Package | Downloads |
|---|---|
|
Workleap.Extensions.MediatR.ApplicationInsights
MediatR extensions, behaviors and default configuration. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.10-preview.10 | 85 | 3/14/2026 |
| 1.5.10-preview.9 | 76 | 3/12/2026 |
| 1.5.10-preview.8 | 72 | 2/27/2026 |
| 1.5.10-preview.7 | 72 | 2/24/2026 |
| 1.5.10-preview.6 | 86 | 2/20/2026 |
| 1.5.10-preview.5 | 83 | 2/12/2026 |
| 1.5.10-preview.4 | 82 | 1/16/2026 |
| 1.5.10-preview.3 | 75 | 1/12/2026 |
| 1.5.10-preview.2 | 95 | 12/31/2025 |
| 1.5.10-preview.1 | 151 | 12/14/2025 |
| 1.5.9 | 24,623 | 11/21/2025 |
| 1.5.9-preview.1 | 306 | 11/21/2025 |
| 1.5.8 | 11,670 | 11/10/2025 |
| 1.5.8-preview.1 | 259 | 11/10/2025 |
| 1.5.7 | 16,147 | 10/19/2025 |
| 1.5.7-preview.1 | 155 | 10/17/2025 |
| 1.5.6 | 3,321 | 10/5/2025 |
| 1.5.6-preview.1 | 177 | 10/2/2025 |
| 1.5.5 | 3,776 | 9/21/2025 |
| 1.5.5-preview.3 | 221 | 9/19/2025 |