Tooark.Mediator.Abstractions 4.7.0

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

Tooark.Mediator.Abstractions

Library with the base contracts of the Mediator pattern for .NET projects, used by implementations such as Tooark.Mediator.

🌍 Languages: πŸ‡ΊπŸ‡Έ English (this file) Β· πŸ‡§πŸ‡· PortuguΓͺs


πŸ“‘ Contents


πŸ“– Overview

The Tooark.Mediator.Abstractions package defines the contracts for:

  • requests (IRequest, IRequest<TResponse>);
  • commands (ICommand, ICommand<TResponse>);
  • queries (IQuery<TResponse>);
  • notifications (INotify);
  • sending and publishing (ISender, IPublisher);
  • the main interface (IMediator);
  • the empty return (Unit).

πŸ”§ Installation

dotnet add package Tooark.Mediator.Abstractions

πŸ“¦ Components

Message contracts

  • IRequest<TResponse>: base contract of a request with a response.
  • IRequest: shortcut for a request without a response payload (Unit).
  • ICommand<TResponse>: command with a response.
  • ICommand: command without an explicit response (Unit).
  • IQuery<TResponse>: query with a response.
  • INotify: notification/event without a response.

Orchestration contracts

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

Utility type

  • Unit
    • Unit.Value: the single instance of Unit.
    • Unit.Task: a task completed with Unit.Value, created once and reused on every access.

πŸ“ Usage Examples

Defining messages

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;

Depending on the contracts in a service

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);
  }
}

Using Unit in commands without a return value

using Tooark.Mediator.Abstractions;

public sealed record DeactivateOrderCommand(Guid Id) : ICommand;

// ICommand is a shortcut for ICommand<Unit>: sending returns Task<Unit>
public sealed class OrderMaintenanceService(ISender sender)
{
  public Task<Unit> DeactivateAsync(Guid id, CancellationToken cancellationToken)
  {
    // Synchronous short-circuit: Unit.Task reuses the pre-built task, with no new allocation
    if (id == Guid.Empty)
    {
      return Unit.Task;
    }

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

πŸ“‹ Dependencies

Package Version Description
Tooark.Exceptions 4.x Exceptions (e.g. BadRequestException)

🀝 Contributing

Contributions are welcome! Start with CONTRIBUTING.md β€” it covers the development workflow, the coding and commit conventions and the pull request checklist. Bugs and feature requests go through the issue templates of the Tooark repository.

By participating you agree to the Code of Conduct.


πŸ†˜ Help & Security

  • ❓ Questions, bugs, feature ideas β€” see SUPPORT.md for the right channel
  • πŸ”’ Security vulnerabilities β€” do not open a public issue; follow SECURITY.md

πŸ’– Support

If Tooark helps your projects, consider supporting its development:

Every contribution helps keep the project maintained and improving. Thank you! πŸ™


πŸ“„ License

This project is licensed under the BSD 3-Clause License.

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.7.0 276 9/30/2026
4.6.0 174 9/29/2026
4.5.0 135 9/29/2026
4.4.0 141 9/28/2026
4.3.0 146 9/26/2026
4.2.1 139 9/25/2026
4.2.0 146 9/20/2026
4.1.0 144 9/18/2026
4.0.1 186 8/25/2026
4.0.0 162 8/25/2026
3.3.6 125 9/18/2026
3.3.5 139 8/25/2026
3.3.4 148 8/12/2026
3.3.3 149 7/27/2026
3.3.2 327 6/11/2026
3.3.1 170 6/6/2026
3.3.0 176 4/17/2026