DSoftStudio.Mediator.Abstractions 1.2.0

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

DSoftStudio.Mediator.Abstractions

NuGet License: MIT

Contracts (interfaces and base types) for DSoftStudio.Mediator. Reference this package in domain, application-core, and test projects that need ISender, IPublisher, IMediator, IRequest, INotification, and related abstractions — without pulling in the runtime or source generators.

Installation

dotnet add package DSoftStudio.Mediator.Abstractions

When to Use This Package

Project type Package to reference Why
Host / Composition root DSoftStudio.Mediator Full runtime + DI registration + source generators
Domain / Application layer DSoftStudio.Mediator.Abstractions ← this one Interfaces only — no generators, no generated code
Unit test project DSoftStudio.Mediator.Abstractions ← this one Fully mock-safe — no interceptors generated

This is the recommended architecture for testability. See the cross-project-mocking sample for a complete working example.

Included Interfaces

Dispatchers

Interface Description
ISender Sends requests (commands/queries) through the pipeline
IPublisher Publishes notifications to all registered handlers
IMediator Combines ISender + IPublisher + stream dispatch

Requests & Handlers

Interface Description
IRequest<TResponse> Marker for a request that returns TResponse
IRequestHandler<TRequest, TResponse> Handles a request and returns a response
ICommand<TResponse> Semantic alias for IRequest<TResponse> — write operations (CQRS)
ICommand Non-generic marker for runtime command detection
ICommandHandler<TCommand, TResponse> Semantic alias for IRequestHandler — command handlers
ICommandHandler<TCommand> Convenience alias for commands returning Unit
IQuery<TResponse> Semantic alias for IRequest<TResponse> — read operations (CQRS)
IQuery Non-generic marker for runtime query detection
IQueryHandler<TQuery, TResponse> Semantic alias for IRequestHandler — query handlers

Notifications

Interface Description
INotification Marker for a notification (domain event)
INotificationHandler<TNotification> Handles a notification — multiple handlers per type
INotificationPublisher Strategy for dispatching notifications (sequential, parallel, custom)

Streams

Interface Description
IStreamRequest<TResponse> Marker for a streaming request returning IAsyncEnumerable<TResponse>
IStreamRequestHandler<TRequest, TResponse> Handles a stream request
IStreamPipelineBehavior<TRequest, TResponse> Pipeline behavior for stream requests

Pipeline

Interface Description
IPipelineBehavior<TRequest, TResponse> Wraps request execution — logging, validation, transactions, etc.
IRequestPreProcessor<TRequest> Runs before the handler — simpler than a full behavior
IRequestPostProcessor<TRequest, TResponse> Runs after the handler — audit logging, caching, etc.
IRequestExceptionHandler<TRequest, TResponse> Handles exceptions — can suppress and provide fallback responses

Types

Type Description
Unit Void return type for requests with no meaningful result
RequestExceptionHandlerState<TResponse> Mutable state for exception handlers to signal handling
MediatorHandlerRegistrationAttribute Assembly-level attribute for cross-project handler discovery

Usage Examples

Define a command and handler

using DSoftStudio.Mediator.Abstractions;

// Command (write operation)
public sealed record CreateOrderCommand(string ProductName, int Quantity) : ICommand<int>;

public sealed class CreateOrderCommandHandler : ICommandHandler<CreateOrderCommand, int>
{
    public ValueTask<int> Handle(CreateOrderCommand request, CancellationToken ct)
    {
        // ... create order logic
        return new(orderId);
    }
}

Define a query and handler

// Query (read operation)
public sealed record GetOrderQuery(int OrderId) : IQuery<string>;

public sealed class GetOrderQueryHandler : IQueryHandler<GetOrderQuery, string>
{
    public ValueTask<string> Handle(GetOrderQuery request, CancellationToken ct)
    {
        return new($"Order #{request.OrderId}");
    }
}

Define a notification and handler

public sealed record OrderPlaced(int OrderId) : INotification;

public sealed class SendOrderEmail : INotificationHandler<OrderPlaced>
{
    public Task Handle(OrderPlaced notification, CancellationToken ct)
    {
        // ... send email
        return Task.CompletedTask;
    }
}

Define a pipeline behavior

public sealed class LoggingBehavior<TRequest, TResponse>
    : IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    public async ValueTask<TResponse> Handle(
        TRequest request,
        IRequestHandler<TRequest, TResponse> next,
        CancellationToken ct)
    {
        Console.WriteLine($"Handling {typeof(TRequest).Name}");
        var response = await next.Handle(request, ct);
        Console.WriteLine($"Handled {typeof(TRequest).Name}");
        return response;
    }
}

Mock ISender in tests

// Always use the explicit two-generic-parameter form:
var sender = new Mock<ISender>();
sender.Setup(s => s.Send<CreateOrderCommand, int>(
        It.IsAny<CreateOrderCommand>(), It.IsAny<CancellationToken>()))
    .ReturnsAsync(1001);

Target Framework

This package targets .NET Standard 2.0 — compatible with .NET 8+, .NET Framework 4.6.1+, and any runtime that supports .NET Standard 2.0.

Package Description
DSoftStudio.Mediator Runtime + DI + source generators
DSoftStudio.Mediator.OpenTelemetry Distributed tracing + metrics
DSoftStudio.Mediator.FluentValidation Automatic request validation
DSoftStudio.Mediator.HybridCache Multi-layer caching

Documentation

Full documentation: docs.dsoftstudio.com/mediator

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DSoftStudio.Mediator.Abstractions:

Package Downloads
DSoftStudio.Mediator

Ultra-low-latency mediator for .NET with compile-time dispatch, zero-allocation pipelines, and a familiar MediatR-style API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 983 4/13/2026
1.1.8 408 3/23/2026