CleanArch.DevKit.Mediator.Behaviors 1.1.1

dotnet add package CleanArch.DevKit.Mediator.Behaviors --version 1.1.1
                    
NuGet\Install-Package CleanArch.DevKit.Mediator.Behaviors -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CleanArch.DevKit.Mediator.Behaviors" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanArch.DevKit.Mediator.Behaviors" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="CleanArch.DevKit.Mediator.Behaviors" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CleanArch.DevKit.Mediator.Behaviors --version 1.1.1
                    
#r "nuget: CleanArch.DevKit.Mediator.Behaviors, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CleanArch.DevKit.Mediator.Behaviors@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CleanArch.DevKit.Mediator.Behaviors&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=CleanArch.DevKit.Mediator.Behaviors&version=1.1.1
                    
Install as a Cake Tool

CleanArch.DevKit.Mediator.Behaviors

Comportements de pipeline prêts à l'emploi pour le médiateur : journalisation, mesure de performance, capture d'exceptions.

Rôle

Fournit trois implémentations d'IPipelineBehavior<,> couvrant les besoins transverses les plus courants (audit, télémétrie, exception). Chaque behavior est enregistré séparément via une extension dédiée, ou tous d'un coup via AddCommonBehaviors() qui applique l'ordre recommandé.

Installation

dotnet add package CleanArch.DevKit.Mediator.Behaviors

Dépend de CleanArch.DevKit.Mediator et de Microsoft.Extensions.Logging.

Fonctionnalités

  • LoggingBehavior — trace l'entrée et la sortie de chaque requête
  • PerformanceBehavior — alerte sur les requêtes lentes (seuil configurable)
  • UnhandledExceptionBehavior — journalise toute exception non gérée
  • Enregistrement individuel ou groupé via AddCommonBehaviors()
  • Ordre d'exécution recommandé

LoggingBehavior

Émet un log Information à l'entrée et à la sortie du handler, et Error en cas d'exception (l'exception est ensuite rejetée). Les annulations (OperationCanceledException) sont loggées en Information, pas en erreur.

services.AddLoggingBehavior();

Sortie typique :

Handling GetUser
Handled GetUser

PerformanceBehavior

Mesure le temps passé dans la suite du pipeline + handler. Émet un log Warning quand la durée dépasse le seuil configuré.

services.AddPerformanceBehavior(o => o.WarningThresholdMs = 200); // défaut : 500 ms

Sortie typique :

GetUser took 712ms (threshold 200ms)

Placer ce behavior le plus profond dans la chaîne pour mesurer le travail réel et non l'overhead des autres behaviors.


UnhandledExceptionBehavior

Capture toute exception non OperationCanceledException, journalise au niveau Error avec le nom de la requête, puis rejette l'exception telle quelle.

services.AddUnhandledExceptionBehavior();

Sortie typique :

Unhandled exception in GetUser: User repository unavailable

Placer ce behavior le plus en surface pour qu'aucun throw n'échappe à la journalisation.


Enregistrer les trois behaviors d'un coup

services.AddMediator();
services.AddCommonBehaviors(o => o.WarningThresholdMs = 100);

Équivalent à l'enregistrement individuel, dans l'ordre recommandé :

  1. UnhandledExceptionBehavior (le plus externe — attrape tout throw)
  2. LoggingBehavior
  3. PerformanceBehavior (le plus interne — mesure le travail réel)

Ordre d'exécution

Les behaviors d'IPipelineBehavior<,> s'exécutent dans l'ordre d'enregistrement, le premier inscrit étant le plus externe. Pour une chaîne A → B → C enregistrée dans cet ordre :

A.Handle(request, next: () =>
    B.Handle(request, next: () =>
        C.Handle(request, next: () =>
            Handler.Handle(request))))

Donc AddCommonBehaviors() produit :

UnhandledException → Logging → Performance → Handler

Quand un behavior tiers doit s'intercaler, l'ordre des appels Add... est ce qui compte.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.1 89 5/17/2026
1.1.0 88 5/17/2026
1.0.0 87 5/15/2026
0.1.0-preview.1 45 5/14/2026