Vortex.Mediator.Abstractions 1.1.1

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

Vortex.Mediator

Vortex.Mediator is a source-generated mediator library for .NET with support for:

  • request/response with Task<T>
  • commands with Task
  • notifications with multiple handlers
  • async streams with IAsyncEnumerable<T>
  • pipeline behaviors
  • convention-based handlers with compile-time dispatch

The runtime package is Vortex.Mediator. It already brings Vortex.Mediator.Abstractions as a transitive dependency.

Installation

For normal application usage, install only Vortex.Mediator.

dotnet add package Vortex.Mediator

If you need only the public contracts in a shared contracts project, install Vortex.Mediator.Abstractions.

dotnet add package Vortex.Mediator.Abstractions

Registering In DI

using Vortex.Mediator.DependencyInjection;

builder.Services.AddVortexMediator();

You can also scan explicit assemblies:

builder.Services.AddVortexMediator(typeof(Program).Assembly);

Usage Modes

1. Interface-Based Handler

using Vortex.Mediator.Abstractions;

public sealed record CreateUserCommand(string Name) : IRequest<Guid>;

public sealed class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
{
    public Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
    {
        return Task.FromResult(Guid.NewGuid());
    }
}

2. Convention-Based Static Handler

using Vortex.Mediator.Abstractions;

public sealed record CreateUserCommand(string Name) : IRequest<Guid>;

public static class CreateUserEndpoint
{
    public static Task<Guid> Handle(
        CreateUserCommand command,
        IUserRepository repository,
        CancellationToken cancellationToken)
    {
        return repository.CreateAsync(command.Name, cancellationToken);
    }
}

3. Convention-Based Instance Handler

using Vortex.Mediator.Abstractions;

public sealed record CreateUserCommand(string Name) : IRequest<Guid>;

public sealed class CreateUserEndpoint(IUserRepository repository)
{
    public Task<Guid> Handle(
        CreateUserCommand command,
        CancellationToken cancellationToken)
    {
        return repository.CreateAsync(command.Name, cancellationToken);
    }
}

For instance handlers, the generated code:

  • first tries to resolve the handler from DI
  • if it is not registered, falls back to ActivatorUtilities.CreateInstance

Sending Requests

var userId = await mediator.Send(new CreateUserCommand("Ada"), cancellationToken);

Command without response:

public sealed record RebuildCacheCommand() : IRequest;

await mediator.Send(new RebuildCacheCommand(), cancellationToken);

Publishing Notifications

public sealed record UserCreated(Guid UserId) : INotification;

await mediator.Publish(new UserCreated(userId), cancellationToken);

Interface-based notification handler:

public sealed class SendWelcomeEmailHandler : INotificationHandler<UserCreated>
{
    public Task Handle(UserCreated notification, CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }
}

Convention-based notification handler:

public static class UserCreatedEndpoint
{
    public static Task Handle(UserCreated notification, IEmailSender emailSender, CancellationToken cancellationToken)
    {
        return emailSender.SendWelcomeAsync(notification.UserId, cancellationToken);
    }
}

Streams

public sealed record GetNumbers(int Count) : IStreamRequest<int>;

public static class NumberStreamEndpoint
{
    public static async IAsyncEnumerable<int> Handle(
        GetNumbers request,
        [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
    {
        for (var index = 1; index <= request.Count; index++)
        {
            cancellationToken.ThrowIfCancellationRequested();
            yield return index;
            await Task.Yield();
        }
    }
}

Consumption:

await foreach (var item in mediator.CreateStream(new GetNumbers(3), cancellationToken))
{
    Console.WriteLine(item);
}

Pipeline Behaviors

Response pipeline:

public sealed class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
    public async Task<TResponse> Handle(
        TRequest request,
        RequestHandlerDelegate<TResponse> next,
        CancellationToken cancellationToken)
    {
        Console.WriteLine(typeof(TRequest).Name);
        return await next();
    }
}

Registration:

builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));

The same pattern exists for:

  • IPipelineBehavior<TRequest> for commands
  • IStreamPipelineBehavior<TRequest, TResponse> for streams

Notes

  • Vortex.Mediator uses source generation for dispatch.
  • Requests, notifications and streams are mapped at compile time.
  • Reflection is not used in the runtime dispatch path.
  • Convention-based handlers and interface-based handlers can coexist.

Development

See CONTRIBUTING.md for contribution guidelines.

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 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 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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

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

Package Downloads
Vortex.Mediator

Source-generated mediator runtime for Vortex.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 139 3/11/2026
1.1.0 138 3/11/2026