Tolitech.Application.Mediator 1.0.0-preview.5

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

Tolitech.Application.Mediator

Overview

Tolitech.Application.Mediator is a modern .NET library that provides essential abstractions for implementing the Mediator pattern, facilitating the separation of commands, queries, and domain events. Built on top of MediatR, it promotes a clean, maintainable, and testable architecture for enterprise applications.

Features

  • Command and Query Abstractions: Interfaces for commands and queries, enabling clear separation of responsibilities.
  • Handler Interfaces: Strongly-typed handler interfaces for commands, queries, and domain events.
  • Domain Event Integration: Support for domain event handling using marker interfaces.
  • Extensibility: Easily integrate with custom business logic and infrastructure.
  • Clean Architecture Alignment: Designed to work seamlessly in layered architectures.

Main Interfaces

ICommand<TResponse>

Represents a command with a response type.

public interface ICommand<out TResponse> : IRequest<TResponse>;

IQuery<TResponse>

Represents a query with a response type.

public interface IQuery<out TResponse> : IRequest<TResponse>;

ICommandHandler<TRequest, TResponse>

Handler for commands.

public interface ICommandHandler<TRequest, TResponse> : IRequestHandler<TRequest, TResponse>
    where TRequest : IRequest<TResponse>;

IQueryHandler<TRequest, TResponse>

Handler for queries.

public interface IQueryHandler<TRequest, TResponse> : IRequestHandler<TRequest, TResponse>
    where TRequest : IRequest<TResponse>;

IDomainEventHandler<TRequest>

Handler for domain events.

public interface IDomainEventHandler<in TRequest> : INotificationHandler<TRequest>
    where TRequest : IDomainEvent;

Example Usage

Command Example

public class CreateOrderCommand : ICommand<OrderResult>
{
    public string ProductId { get; set; }
    public int Quantity { get; set; }
}

public class CreateOrderCommandHandler : ICommandHandler<CreateOrderCommand, OrderResult>
{
    public async Task<OrderResult> Handle(CreateOrderCommand command, CancellationToken cancellationToken)
    {
        // Business logic to create order
        return new OrderResult { Success = true };
    }
}

Query Example

public class GetOrderQuery : IQuery<Order>
{
    public Guid OrderId { get; set; }
}

public class GetOrderQueryHandler : IQueryHandler<GetOrderQuery, Order>
{
    public async Task<Order> Handle(GetOrderQuery query, CancellationToken cancellationToken)
    {
        // Business logic to retrieve order
        return new Order { Id = query.OrderId };
    }
}

Domain Event Example

public class OrderCreatedEvent : IDomainEvent
{
    public Guid OrderId { get; set; }
}

public class OrderCreatedEventHandler : IDomainEventHandler<OrderCreatedEvent>
{
    public async Task Handle(OrderCreatedEvent notification, CancellationToken cancellationToken)
    {
        // Logic to handle event
    }
}

Integration Steps

  1. Reference Tolitech.Application.Mediator in your project.
  2. Define your commands, queries, and domain events using the provided interfaces.
  3. Implement the corresponding handler interfaces.
  4. Register handlers with MediatR in your dependency injection container.
  5. Use MediatR's IMediator to send commands/queries and publish events.

Summary

Tolitech.Application.Mediator streamlines the implementation of the Mediator pattern in .NET, providing a robust foundation for scalable, maintainable, and testable applications.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 was computed.  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.0.0-preview.5 439 7/21/2025
1.0.0-preview.4 117 7/7/2025
1.0.0-preview.3 122 7/3/2025
1.0.0-preview.2 123 7/3/2025
1.0.0-preview.1 102 12/11/2024