Tooark.Mediator 3.3.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tooark.Mediator --version 3.3.3
                    
NuGet\Install-Package Tooark.Mediator -Version 3.3.3
                    
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="Tooark.Mediator" Version="3.3.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tooark.Mediator" Version="3.3.3" />
                    
Directory.Packages.props
<PackageReference Include="Tooark.Mediator" />
                    
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 Tooark.Mediator --version 3.3.3
                    
#r "nuget: Tooark.Mediator, 3.3.3"
                    
#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 Tooark.Mediator@3.3.3
                    
#: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=Tooark.Mediator&version=3.3.3
                    
Install as a Cake Addin
#tool nuget:?package=Tooark.Mediator&version=3.3.3
                    
Install as a Cake Tool

Tooark.Mediator

Biblioteca com implementação de Mediator para projetos .NET, focada em CQRS/CQS com baixo acoplamento entre camadas.

Conteúdo

Visão Geral

O pacote Tooark.Mediator fornece:

  • implementação concreta de IMediator;
  • registro automático de handlers por assembly;
  • estratégia configurável de publicação de notificações;
  • integração com DI do Microsoft.Extensions.DependencyInjection.

🔧 Instalação

dotnet add package Tooark.Mediator

⚙️ Configuração

using Tooark.Mediator.Injections;

builder.Services.AddTooarkMediator(typeof(Program).Assembly);

Também é possível configurar as opções do mediador:

using Tooark.Mediator.Enums;
using Tooark.Mediator.Injections;

builder.Services.AddTooarkMediator(options =>
{
  options.NotifyPublishStrategy = ENotifyStrategy.Sequential;
}, typeof(Program).Assembly);

📦 Componentes

Classe principal

  • Mediator: implementação de IMediator.

Injeção de dependência

  • TooarkDependencyInjection.AddTooarkMediator(IServiceCollection, params Assembly[])
  • TooarkDependencyInjection.AddTooarkMediator(IServiceCollection, Action<MediatorOptions>, params Assembly[])

Opções

  • MediatorOptions
    • NotifyPublishStrategy (padrão: ENotifyStrategy.ParallelWhenAll)

Estratégias de publicação

  • ENotifyStrategy.ParallelWhenAll
  • ENotifyStrategy.Sequential

Handlers suportados

  • IRequestHandler<TRequest, TResponse>
  • ICommandHandler<TCommand, TResponse>
  • ICommandHandler<TCommand>
  • IQueryHandler<TQuery, TResponse>
  • INotifyHandler<TNotify>

📝 Exemplos de Uso

Exemplo CQRS

using Tooark.Mediator.Abstractions;
using Tooark.Mediator.Handlers;

public sealed record CreateUserCommand(string Name) : ICommand<Guid>;

public sealed class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, Guid>
{
  public Task<Guid> HandleAsync(CreateUserCommand request, CancellationToken cancellationToken = default)
  {
    return Task.FromResult(Guid.NewGuid());
  }
}

public sealed record GetUserByIdQuery(Guid Id) : IQuery<string>;

public sealed class GetUserByIdQueryHandler : IQueryHandler<GetUserByIdQuery, string>
{
  public Task<string> HandleAsync(GetUserByIdQuery request, CancellationToken cancellationToken = default)
  {
    return Task.FromResult($"Usuário {request.Id}");
  }
}

Exemplo de uso com IMediator

using Tooark.Mediator.Abstractions;

public sealed class UsersService(IMediator mediator)
{
  public Task<Guid> CreateAsync(string name, CancellationToken cancellationToken)
  {
    return mediator.SendAsync(new CreateUserCommand(name), cancellationToken);
  }

  public Task<string> GetAsync(Guid id, CancellationToken cancellationToken)
  {
    return mediator.SendAsync(new GetUserByIdQuery(id), cancellationToken);
  }
}

Exemplo de publicação de notificação

using Tooark.Mediator.Abstractions;
using Tooark.Mediator.Handlers;

public sealed record UserCreatedNotify(Guid UserId) : INotify;

public sealed class UserCreatedNotifyHandler : INotifyHandler<UserCreatedNotify>
{
  public Task HandleAsync(UserCreatedNotify notification, CancellationToken cancellationToken = default)
  {
    Console.WriteLine($"Usuário criado: {notification.UserId}");
    return Task.CompletedTask;
  }
}

await mediator.PublishAsync(new UserCreatedNotify(Guid.NewGuid()), cancellationToken);

📋 Dependências

Pacote Versão Descrição
Tooark.Exceptions — Exceções (ex.: BadRequestException)
Tooark.Mediator.Abstractions — Contratos base do padrão Mediator
Microsoft.Extensions.DependencyInjection.Abstractions 8.x Abstrações de injeção de dependência

🪪 Contribuição

Contribuições são bem-vindas! Sinta-se à vontade para abrir issues e pull requests no repositório Tooark.Mediator.

📄 Licença

Este projeto está licenciado sob a licença BSD 3-Clause. Veja o arquivo LICENSE para mais detalhes.

Product Compatible and additional computed target framework versions.
.NET 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 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 (2)

Showing the top 2 NuGet packages that depend on Tooark.Mediator:

Package Downloads
Tooark

Package with all Tooark resources for .NET applications.

Tooark.Mediator.EntityFrameworkCore

Library that moves Entity Framework Core persistence into the Tooark.Mediator pipeline, keeping handlers free of SaveChanges.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.7.1 0 10/17/2026
4.7.0 285 9/30/2026
4.6.0 160 9/29/2026
4.5.0 124 9/29/2026
4.4.0 125 9/28/2026
4.3.0 135 9/26/2026
4.2.1 133 9/25/2026
4.2.0 135 9/20/2026
4.1.0 130 9/18/2026
4.0.1 174 8/25/2026
4.0.0 163 8/25/2026
3.3.6 105 9/18/2026
3.3.5 123 8/25/2026
3.3.4 131 8/12/2026
3.3.3 145 7/27/2026
3.3.2 303 6/11/2026
3.3.1 153 6/6/2026
3.3.0 160 4/17/2026