DandyMediator 10.0.2

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

Whats DandyMediator?

Honestly, just yet another interpretation of the mediator pattern, based on the concepts of JBogard's MediatR. Just with a little of extra spice from my end, catered to my taste.

Overview

What can DandyMediator do?

DandyMediator should generally be able to do anything MediatR can and its API is largely the same, with exceptions like the naming of asynchronous methods (like HandleAsync instead of Handle), just to name an example. The configuration API however does not have that many options yet. Thats mostly because I have not needed anything other than scanning for services in assemblies yet.

However I added native markup-interfaces such as ICommand, IQuery and their respective handler-interfaces to cater to CQRS-like application-architecture, since thats what I am aiming for in a lot of my projects. I also added an IRequestResponse (and a generic variant) with a status code that mimics HTTP status codes, but using that interface is entirely optional (as is using the query and command APIs). When using the ICommand and IQuery markup-interfaces, the request responses are implicitly used by default without a way of opting out.

Validation via attributes of request properties

The package DandyMediator.Validation adds automatic validation of properties (includes primary constructor parameters for records). If any property is deemed not valid, a response resembling Bad Request and the occurred validation errors is returned. This allows automizing something as common as validation. However since an IRequestResponse is used as a return type, validation will not work when implementing requests without using an IRequestResponse as the requests return type.

Validation could look just like this:

internal sealed record RegisterUserCommand(
    [Required, MinLength(1), MaxLength(255)] string LoginName,
    [Required, MinLength(12)] string Password) : ICommand<Guid>;

How do I use it?

I use DandyMediator in combination with my other package DandyEndpoints for my interpretation of vertical slicing for every HTTP endpoint my APIs process. Have a look at this quick example:

internal static class GetTeamById
{
    private sealed class Endpoint : IEndpoint
    {
        public void Map(IEndpointRouteBuilder app)
        {
            app.MapGet("/teams/{teamId}", async ([FromServices] IMediator mediator, Guid teamId, CancellationToken cancellationToken) =>
            {
                var response = await mediator.SendAsync<Query, Team>(new Query(teamId), cancellationToken);
                return response.ToResult();
            });
        }
    }

    private sealed record Query(Guid TeamId) : IQuery<Team>;

    private sealed class QueryHandler(IUnitOfWork _unitOfWork) : IQueryHandler<Query, Team>
    {
        public async Task<IQueryResponse<Team>> HandleAsync(Query request, CancellationToken cancellationToken)
        {
            var team = await _unitOfWork.Repository<ITeamRepository>().GetByIdAsync(request.TeamId, cancellationToken);
            return QueryResponseFactory.OkOrBadRequest(team).Build();
        }
    }
}

Setup

You setup DandyMediator exactly like you would any other framework for an ASP.NET Core webapi. Have a quick look at this basic minimal setup:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi();
builder.Services.AddDandyMediator(configuration =>      // <- Just add this, just like you would expect
{
    configuration.ScanInAssemblies(typeof(Program).Assembly);
});

var app = builder.Build();
if (app.Environment.IsDevelopment())
    app.MapOpenApi();

app.UseHttpsRedirection();

app.Run();

Adding the validation plugin

Validation is configured using the DandyMediatorConfigurationBuilder when adding DandyMediator to the WebApplicationBuilders IServiceCollection:

builder.Services.AddDandyMediator(configuration =>
{
    configuration.ScanInAssemblies(typeof(Program).Assembly);
    configuration.UseValidation();     // <- This line
});
Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DandyMediator:

Package Downloads
DandyMediator.Validation

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.2 85 5/7/2026