Tooark.Mediator.Abstractions 4.0.1

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

Tooark.Mediator.Abstractions

Biblioteca com os contratos base do padrão Mediator para projetos .NET, utilizada por implementações como Tooark.Mediator.

Conteúdo

Visão Geral

O pacote Tooark.Mediator.Abstractions define os contratos para:

  • requests (IRequest, IRequest<TResponse>);
  • commands (ICommand, ICommand<TResponse>);
  • queries (IQuery<TResponse>);
  • notifications (INotify);
  • envio e publicação (ISender, IPublisher);
  • interface principal (IMediator);
  • retorno vazio (Unit).

🔧 Instalação

dotnet add package Tooark.Mediator.Abstractions

📦 Componentes

Contratos de mensagem

  • IRequest<TResponse>: contrato base de requisição com resposta.
  • IRequest: atalho para requisição sem payload de resposta (Unit).
  • ICommand<TResponse>: comando com resposta.
  • ICommand: comando sem resposta explícita (Unit).
  • IQuery<TResponse>: consulta com resposta.
  • INotify: notificação/evento sem resposta.

Contratos de orquestração

  • ISender
    • Task<TResponse> SendAsync<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default)
  • IPublisher
    • Task PublishAsync(INotify notify, CancellationToken cancellationToken = default)
  • IMediator: combina ISender e IPublisher.

Tipo utilitário

  • Unit
    • Unit.Value: a única instância de Unit.
    • Unit.Task: tarefa concluída com Unit.Value, criada uma única vez e reutilizada a cada acesso.

📝 Exemplos de Uso

Definindo mensagens

using Tooark.Mediator.Abstractions;

public sealed record CreateOrderCommand(string CustomerName) : ICommand<Guid>;

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

public sealed record OrderCreatedNotify(Guid OrderId) : INotify;

Dependendo dos contratos no serviço

using Tooark.Mediator.Abstractions;

public sealed class OrderApplicationService(ISender sender, IPublisher publisher)
{
  public async Task<Guid> CreateAsync(string customerName, CancellationToken cancellationToken)
  {
    var id = await sender.SendAsync(new CreateOrderCommand(customerName), cancellationToken);

    await publisher.PublishAsync(new OrderCreatedNotify(id), cancellationToken);

    return id;
  }

  public Task<string> GetByIdAsync(Guid id, CancellationToken cancellationToken)
  {
    return sender.SendAsync(new GetOrderByIdQuery(id), cancellationToken);
  }
}

Usando Unit em comandos sem retorno

using Tooark.Mediator.Abstractions;

public sealed record DeactivateOrderCommand(Guid Id) : ICommand;

// ICommand é atalho para ICommand<Unit>: o envio retorna Task<Unit>
public sealed class OrderMaintenanceService(ISender sender)
{
  public Task<Unit> DeactivateAsync(Guid id, CancellationToken cancellationToken)
  {
    // Curto-circuito síncrono: Unit.Task reutiliza a tarefa pré-construída, sem nova alocação
    if (id == Guid.Empty)
    {
      return Unit.Task;
    }

    return sender.SendAsync(new DeactivateOrderCommand(id), cancellationToken);
  }
}

📋 Dependências

Pacote Versão Descrição
Tooark.Exceptions 4.x Exceções (ex.: BadRequestException)

🪪 Contribuição

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

📄 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 (3)

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

Package Downloads
Tooark

Package with all Tooark resources for .NET applications.

Tooark.Mediator

Library for decoupling requests and handlers with the Mediator pattern in .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.0.1 151 8/25/2026
4.0.0 135 8/25/2026
3.3.5 117 8/25/2026
3.3.4 121 8/12/2026
3.3.3 131 7/27/2026
3.3.2 312 6/11/2026
3.3.1 157 6/6/2026
3.3.0 165 4/17/2026