Tolitech.Application.Mediator
1.0.0-preview.5
dotnet add package Tolitech.Application.Mediator --version 1.0.0-preview.5
NuGet\Install-Package Tolitech.Application.Mediator -Version 1.0.0-preview.5
<PackageReference Include="Tolitech.Application.Mediator" Version="1.0.0-preview.5" />
<PackageVersion Include="Tolitech.Application.Mediator" Version="1.0.0-preview.5" />
<PackageReference Include="Tolitech.Application.Mediator" />
paket add Tolitech.Application.Mediator --version 1.0.0-preview.5
#r "nuget: Tolitech.Application.Mediator, 1.0.0-preview.5"
#:package Tolitech.Application.Mediator@1.0.0-preview.5
#addin nuget:?package=Tolitech.Application.Mediator&version=1.0.0-preview.5&prerelease
#tool nuget:?package=Tolitech.Application.Mediator&version=1.0.0-preview.5&prerelease
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
- Reference Tolitech.Application.Mediator in your project.
- Define your commands, queries, and domain events using the provided interfaces.
- Implement the corresponding handler interfaces.
- Register handlers with MediatR in your dependency injection container.
- 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 | Versions 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. |
-
net9.0
- MediatR (>= 12.5.0)
- Tolitech.Domain (>= 1.0.0-preview.7)
- Tolitech.Results (>= 1.0.0-preview.4)
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 |