FBC.Mediator
0.0.1
dotnet add package FBC.Mediator --version 0.0.1
NuGet\Install-Package FBC.Mediator -Version 0.0.1
<PackageReference Include="FBC.Mediator" Version="0.0.1" />
<PackageVersion Include="FBC.Mediator" Version="0.0.1" />
<PackageReference Include="FBC.Mediator" />
paket add FBC.Mediator --version 0.0.1
#r "nuget: FBC.Mediator, 0.0.1"
#:package FBC.Mediator@0.0.1
#addin nuget:?package=FBC.Mediator&version=0.0.1
#tool nuget:?package=FBC.Mediator&version=0.0.1
FBC.Mediator
FBC.Mediator is a lightweight, high-performance Mediator pattern implementation for .NET projects.
It provides command/query dispatching, request handler caching, and endpoint registration for ASP.NET Core.
Features
IMediatorfor type-safe request/response and void requests- Supports
IRequestHandler<TRequest, TResponse>andIRequestHandler<TRequest> - Request handler caching for performance
- Easy integration with ASP.NET Core Minimal APIs
- Compatible with Swagger/OpenAPI
- Auto-registration of handlers and endpoints
Installation
// In Startup.cs or Program.cs
builder.Services.AddMediator(typeof(Program).Assembly);
...
var app = builder.Build();
...
app.UseMediatorEndpoints();
...
You can pass multiple assemblies if your handlers or endpoints are spread across projects.
Usage
Request & Response
Define a request:
public sealed class CreateItem
{
public record Command(string Name) : IRequest<long>;
internal sealed class Handler(ILogger<Handler> logger) : IRequestHandler<Command, long>
{
public async Task<long> Handle(Command request, CancellationToken token = default)
{
logger.LogInformation("Creating item with Name: {ItemName}", request.Name);
// Perform your logic here
await Task.Delay(100, token); // simulated async operation
return new Random().Next(1, 1000); // example ID
}
}
}
Define an endpoint:
public sealed class CreateItemEndPoint : IEndpoint
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapPost("/items/create", async (CreateItem.Command command, IMediator mediator, CancellationToken token) =>
{
var itemId = await mediator.Send(command, token);
return Results.Ok(itemId);
})
.WithTags("Items")
.WithName("CreateItem")
.WithSummary("Creates a new item.")
.WithDescription("Creates a new item and returns the ID of the created item.")
.Produces<long>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.Produces(StatusCodes.Status500InternalServerError);
}
}
Void Request
Use a void request:
public sealed class VoidTest
{
public record Command() : IRequest;
internal sealed class Handler(ILogger<Handler> logger) : IRequestHandler<Command>
{
public async Task Handle(Command request, CancellationToken token = default)
{
logger.LogInformation("Handling void command");
await Task.CompletedTask;
}
}
}
Endpoint for void request:
public sealed class VoidTestEndPoint : IEndpoint
{
public void AddRoutes(IEndpointRouteBuilder app)
{
app.MapPost("/voidtest", async (VoidTest.Command command, IMediator mediator, CancellationToken token) =>
{
await mediator.Send(command, token);
return Results.Ok();
})
.WithTags("Test")
.WithName("VoidTest")
.WithSummary("Tests void command.")
.WithDescription("Sends a void command and returns OK.")
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.Produces(StatusCodes.Status500InternalServerError);
}
}
DI and Endpoint Integration
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMediator(typeof(Program).Assembly);
var app = builder.Build();
app.UseMediatorEndpoints();
AddMediatorautomatically registers all handlers and endpoints.UseMediatorEndpointsmaps allIEndpointimplementations to the route builder.
Swagger/OpenAPI Support
FBC.Mediator includes a safe schema ID selector for Swagger, ensuring nested classes or records display correctly.
Summary
- Type-safe, generic, and high-performance mediator
- Minimal API-friendly
- Handler caching for fast request dispatch
- Supports void and generic requests
- Compatible with Swagger/OpenAPI
Recommended Usage
- Use
IRequest<TResponse>for commands and queries. - Use
IRequestfor void operations. - Define endpoints using
IEndpoint. - Register the mediator using
AddMediator. - Map endpoints using
UseMediatorEndpoints.
| Product | Versions 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 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. |
-
net8.0
- No dependencies.
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 |
|---|---|---|
| 0.0.1 | 231 | 12/6/2025 |