Workleap.Extensions.MediatR.ApplicationInsights
1.4.5
Prefix Reserved
See the version list below for details.
dotnet add package Workleap.Extensions.MediatR.ApplicationInsights --version 1.4.5
NuGet\Install-Package Workleap.Extensions.MediatR.ApplicationInsights -Version 1.4.5
<PackageReference Include="Workleap.Extensions.MediatR.ApplicationInsights" Version="1.4.5" />
<PackageVersion Include="Workleap.Extensions.MediatR.ApplicationInsights" Version="1.4.5" />
<PackageReference Include="Workleap.Extensions.MediatR.ApplicationInsights" />
paket add Workleap.Extensions.MediatR.ApplicationInsights --version 1.4.5
#r "nuget: Workleap.Extensions.MediatR.ApplicationInsights, 1.4.5"
#:package Workleap.Extensions.MediatR.ApplicationInsights@1.4.5
#addin nuget:?package=Workleap.Extensions.MediatR.ApplicationInsights&version=1.4.5
#tool nuget:?package=Workleap.Extensions.MediatR.ApplicationInsights&version=1.4.5
Workleap.Extensions.MediatR
This library ensures that MediatR is registered in the dependency injection container as a singleton and also adds several features:
- Activity-based OpenTelemetry instrumentation
- High-performance logging with
Debuglog level - Data annotations support for request validation, similar to ASP.NET Core model validation
- Application Insights instrumentation (in a separate NuGet package)
- CQRS conventions and MediatR best practices with Roslyn analyzers
Getting started
Use 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);
Example
// 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);
Included Roslyn analyzers
| 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.
Building, releasing and versioning
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.
License
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 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.ApplicationInsights (>= 2.23.0)
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Workleap.Extensions.MediatR (>= 1.4.5)
-
net8.0
- Microsoft.ApplicationInsights (>= 2.23.0)
- Workleap.Extensions.MediatR (>= 1.4.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.1 | 11 | 8/17/2025 |
| 1.5.1-preview.1 | 93 | 8/14/2025 |
| 1.5.0 | 93 | 8/14/2025 |
| 1.4.16-preview.1 | 89 | 8/14/2025 |
| 1.4.15 | 54 | 8/10/2025 |
| 1.4.15-preview.1 | 121 | 8/8/2025 |
| 1.4.14 | 210 | 7/27/2025 |
| 1.4.14-preview.3 | 477 | 7/22/2025 |
| 1.4.14-preview.2 | 432 | 7/21/2025 |
| 1.4.14-preview.1 | 272 | 7/21/2025 |
| 1.4.13 | 260 | 7/20/2025 |
| 1.4.13-preview.1 | 101 | 7/18/2025 |
| 1.4.12 | 174 | 7/13/2025 |
| 1.4.12-preview.2 | 42 | 7/12/2025 |
| 1.4.12-preview.1 | 111 | 7/10/2025 |
| 1.4.11 | 434 | 6/29/2025 |
| 1.4.11-preview.1 | 112 | 6/18/2025 |
| 1.4.10 | 579 | 6/15/2025 |
| 1.4.10-preview.2 | 104 | 6/14/2025 |
| 1.4.10-preview.1 | 259 | 6/12/2025 |
| 1.4.9 | 570 | 6/8/2025 |
| 1.4.9-preview.1 | 98 | 6/8/2025 |
| 1.4.8 | 691 | 5/25/2025 |
| 1.4.8-preview.1 | 53 | 5/24/2025 |
| 1.4.7 | 416 | 5/18/2025 |
| 1.4.7-preview.1 | 107 | 5/17/2025 |
| 1.4.6 | 621 | 5/11/2025 |
| 1.4.6-preview.1 | 126 | 5/8/2025 |
| 1.4.5 | 1,654 | 4/14/2025 |
| 1.4.5-preview.1 | 165 | 4/14/2025 |
| 1.4.4-preview.2 | 88 | 4/11/2025 |
| 1.4.4-preview.1 | 88 | 4/11/2025 |
| 1.4.3-preview.9 | 135 | 4/7/2025 |
| 1.4.3-preview.8 | 130 | 4/1/2025 |
| 1.4.3-preview.7 | 136 | 4/1/2025 |
| 1.4.3-preview.5 | 128 | 3/20/2025 |
| 1.4.3-preview.4 | 50 | 3/15/2025 |
| 1.4.3-preview.3 | 141 | 3/11/2025 |
| 1.4.3-preview.2 | 75 | 2/24/2025 |
| 1.4.3-preview.1 | 79 | 2/18/2025 |
| 1.4.2 | 1,231 | 2/17/2025 |
| 1.4.2-preview.24 | 80 | 2/17/2025 |
| 1.4.2-preview.23 | 72 | 2/16/2025 |
| 1.4.2-preview.22 | 81 | 2/15/2025 |
| 1.4.2-preview.21 | 75 | 2/13/2025 |
| 1.4.2-preview.20 | 78 | 2/12/2025 |
| 1.4.2-preview.19 | 72 | 2/3/2025 |
| 1.4.2-preview.18 | 83 | 2/3/2025 |
| 1.4.2-preview.17 | 73 | 1/30/2025 |
| 1.4.2-preview.16 | 60 | 1/17/2025 |
| 1.4.2-preview.15 | 60 | 1/13/2025 |
| 1.4.2-preview.14 | 79 | 12/18/2024 |
| 1.4.2-preview.13 | 70 | 11/29/2024 |
| 1.4.2-preview.12 | 65 | 11/24/2024 |
| 1.4.2-preview.11 | 69 | 11/16/2024 |
| 1.4.2-preview.10 | 65 | 10/31/2024 |
| 1.4.2-preview.9 | 64 | 10/30/2024 |
| 1.4.2-preview.8 | 76 | 10/28/2024 |
| 1.4.2-preview.7 | 66 | 10/28/2024 |
| 1.4.2-preview.6 | 67 | 10/28/2024 |
| 1.4.2-preview.5 | 67 | 10/7/2024 |
| 1.4.2-preview.4 | 79 | 10/1/2024 |
| 1.4.2-preview.3 | 72 | 10/1/2024 |
| 1.4.2-preview.1 | 73 | 9/27/2024 |
| 1.4.1 | 7,115 | 9/20/2024 |
| 1.4.1-preview.10 | 63 | 9/20/2024 |
| 1.4.1-preview.9 | 70 | 9/20/2024 |
| 1.4.1-preview.8 | 67 | 9/20/2024 |
| 1.4.1-preview.7 | 71 | 9/13/2024 |
| 1.4.1-preview.6 | 71 | 8/28/2024 |
| 1.4.1-preview.5 | 66 | 8/27/2024 |
| 1.4.1-preview.4 | 65 | 8/27/2024 |
| 1.4.1-preview.3 | 62 | 8/27/2024 |
| 1.4.1-preview.2 | 87 | 8/16/2024 |
| 1.4.1-preview.1 | 89 | 8/16/2024 |
| 1.4.0 | 1,587 | 7/31/2024 |
| 1.3.1-preview.20 | 55 | 7/31/2024 |
| 1.3.1-preview.19 | 77 | 7/15/2024 |
| 1.3.1-preview.18 | 58 | 7/5/2024 |
| 1.3.1-preview.17 | 80 | 6/10/2024 |
| 1.3.1-preview.16 | 76 | 5/31/2024 |
| 1.3.1-preview.15 | 73 | 5/31/2024 |
| 1.3.1-preview.14 | 68 | 5/28/2024 |
| 1.3.1-preview.13 | 74 | 5/21/2024 |
| 1.3.1-preview.12 | 83 | 5/10/2024 |
| 1.3.1-preview.11 | 95 | 4/12/2024 |
| 1.3.1-preview.10 | 89 | 4/3/2024 |
| 1.3.1-preview.9 | 82 | 4/3/2024 |
| 1.3.1-preview.8 | 78 | 3/8/2024 |
| 1.3.1-preview.7 | 75 | 3/7/2024 |
| 1.3.1-preview.6 | 72 | 3/4/2024 |
| 1.3.1-preview.5 | 85 | 3/1/2024 |
| 1.3.1-preview.4 | 89 | 2/16/2024 |
| 1.3.1-preview.3 | 87 | 2/12/2024 |
| 1.3.1-preview.2 | 86 | 2/6/2024 |
| 1.3.1-preview.1 | 86 | 2/6/2024 |
| 1.3.0 | 24,510 | 1/15/2024 |
| 1.2.1-preview.8 | 90 | 1/15/2024 |
| 1.2.1-preview.7 | 80 | 1/12/2024 |
| 1.2.1-preview.6 | 69 | 1/12/2024 |
| 1.2.1-preview.5 | 71 | 1/12/2024 |
| 1.2.1-preview.4 | 79 | 1/12/2024 |
| 1.2.1-preview.3 | 98 | 12/18/2023 |
| 1.2.1-preview.2 | 98 | 12/7/2023 |
| 1.2.1-preview.1 | 111 | 11/17/2023 |
| 1.2.0 | 8,925 | 11/15/2023 |
| 1.1.4-preview.14 | 81 | 11/14/2023 |
| 1.1.4-preview.13 | 85 | 11/13/2023 |
| 1.1.4-preview.12 | 88 | 11/13/2023 |
| 1.1.4-preview.11 | 100 | 11/6/2023 |
| 1.1.4-preview.10 | 101 | 10/30/2023 |
| 1.1.4-preview.9 | 107 | 10/20/2023 |
| 1.1.4-preview.8 | 103 | 10/17/2023 |
| 1.1.4-preview.7 | 113 | 10/13/2023 |
| 1.1.4-preview.6 | 96 | 9/26/2023 |
| 1.1.4-preview.5 | 105 | 9/25/2023 |
| 1.1.4-preview.4 | 93 | 9/21/2023 |
| 1.1.4-preview.3 | 95 | 9/20/2023 |
| 1.1.4-preview.2 | 94 | 9/20/2023 |
| 1.1.4-preview.1 | 87 | 9/20/2023 |
| 1.1.3 | 39,641 | 9/11/2023 |
| 1.1.3-preview.2 | 119 | 9/11/2023 |
| 1.1.3-preview.1 | 127 | 8/9/2023 |
| 1.1.2 | 238 | 7/20/2023 |
| 1.1.2-preview.7 | 139 | 7/20/2023 |