Biss.Mediator.Behaviors 2.0.0

dotnet add package Biss.Mediator.Behaviors --version 2.0.0
                    
NuGet\Install-Package Biss.Mediator.Behaviors -Version 2.0.0
                    
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="Biss.Mediator.Behaviors" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Biss.Mediator.Behaviors" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Biss.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 Biss.Mediator.Behaviors --version 2.0.0
                    
#r "nuget: Biss.Mediator.Behaviors, 2.0.0"
                    
#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 Biss.Mediator.Behaviors@2.0.0
                    
#: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=Biss.Mediator.Behaviors&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Biss.Mediator.Behaviors&version=2.0.0
                    
Install as a Cake Tool

Biss.Mediator.Behaviors

Pipeline behaviors pré-implementados para Biss.Mediator.

📦 Instalação

dotnet add package Biss.Mediator.Behaviors

🎯 Behaviors Disponíveis

1. LoggingBehavior

Regista logs de todas as requisições e seus resultados (tipo do pedido, duração; em falhas de Result, código e mensagem do erro). Não coloques dados sensíveis em Error.Message se usares este behavior. O README raiz do repositório tem uma secção Privacidade (logs e cache).

services.AddMediatorLoggingBehavior();

2. ValidationBehavior

Executa primeiro FluentValidation (todos os IValidator<TRequest> registados no DI) e depois Data Annotations no modelo do pedido.

// Opcional: validadores FluentValidation (pacote FluentValidation.DependencyInjectionExtensions)
services.AddValidatorsFromAssemblyContaining<Program>();

services.AddMediatorValidationBehavior();

3. PerformanceBehavior

Monitora performance e alerta sobre requisições lentas.

services.AddMediatorPerformanceBehavior(
    slowRequestThreshold: TimeSpan.FromMilliseconds(1000));

4. CachingBehavior

Adiciona cache automático para queries.

O CachingBehavior resolve IMemoryCache — regista o cache em memória antes (ou usa um pacote que o faça):

services.AddMemoryCache();
services.AddMediatorCachingBehavior(
    defaultCacheDuration: TimeSpan.FromMinutes(5));

A chave de cache usa o nome completo do tipo do pedido + hash SHA-256 (hex) de um JSON das propriedades públicas (ver código). Evita cachear queries cujo payload inclua PII sem avaliação de risco.

5. RetryBehavior

Implementa retry automático para requisições que falham.

services.AddMediatorRetryBehavior(
    maxRetryAttempts: 3,
    delayBetweenRetries: TimeSpan.FromMilliseconds(500));

6. TransactionBehavior

Gerencia transações de banco de dados automaticamente.

services.AddMediatorTransactionBehavior();

🚀 Uso Completo

using Biss.Mediator.Behaviors;

services.AddMemoryCache(); // necessário se usares cache (CachingBehavior nas opções)

// Adicionar todos os behaviors de uma vez
services.AddMediatorBehaviors(options =>
{
    options.SlowRequestThreshold = TimeSpan.FromMilliseconds(1000);
    options.DefaultCacheDuration = TimeSpan.FromMinutes(5);
    options.MaxRetryAttempts = 3;
});

Dependências

Este pacote referencia:

  • Biss.Mediator.Abstractions
  • FluentValidation (usado pelo ValidationBehavior)

Na aplicação, para registar IValidator<T> no DI, usa normalmente o pacote FluentValidation.DependencyInjectionExtensions (ex.: AddValidatorsFromAssemblyContaining<Program>()).

Licença

MIT License

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
2.0.0 157 4/22/2026
1.2.0 137 4/6/2026
1.0.0 349 12/7/2025