Geekeey.Request.Dispatcher (2.0.0)

Published 2026-05-30 18:06:41 +00:00 by HeyGeekeey in geekeey/request

Installation

dotnet nuget add source --name geekeey --username your_username --password your_token 
dotnet add package --source geekeey --version 2.0.0 Geekeey.Request.Dispatcher

About this package

Simple mediator implementation in .NET with minimal dependencies.

Features

  • Simple interfaces: no complex constraints, just marker interfaces that work.
  • Minmal dependencies: only depends on Microsoft.Extensions.DependencyInjection.Abstractions and the Microsoft.Extensions.Options package.

Getting Started

Install the NuGet package:

dotnet add package Geekeey.Request.Dispatcher

You may need to add our NuGet feed to your nuget.config this can be done by running the following command:

dotnet nuget add source -n geekeey https://code.geekeey.de/api/packages/geekeey/nuget/index.json

Usage

public static Task<int> Main()
{
  var collection = new ServiceCollection();
  collection.AddRequestDispatcher(builder => builder
      .SearchHandlerInAssembly(typeof(ScalarHandler).Assembly)
      .Add(typeof(ScalarBehavior)));
  await using var provider = collection.BuildServiceProvider();
  var dispatcher = provider.GetRequiredService<IRequestDispatcher>();

  var request = new ScalarRequest { Value = "Hello" };
  var result = await dispatcher.DispatchAsync(request);

  Console.WriteLine(result);
  return 0;
}

public class ScalarRequest : IScalarRequest<string>
{
  public string Value { get; set; } = string.Empty;
}

public class ScalarHandler : IScalarRequestHandler<ScalarRequest, string>
{
  public Task<string> HandleAsync(ScalarRequest request, CancellationToken cancellationToken)
  {
    return Task.FromResult($"{request.Value} World");
  }
}

public class ScalarBehavior : IScalarRequestBehavior<ScalarRequest, string>
{
  public async Task<string> HandleAsync(ScalarRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
  {
    Console.WriteLine("Before");
    var result = await next(request, cancellationToken);
    Console.WriteLine("After");
    return result;
  }
}

Behaviour of the Handlers

Handlers are resolved from either the DI container or are created on the fly but can receive arguments from the DI container when being constructed. The same also applied for the request pipeline behaviours.

Dependencies

ID Version Target Framework
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.6 net10.0
Microsoft.Extensions.Options 10.0.6 net10.0
Details
NuGet
2026-05-30 18:06:41 +00:00
3
The Geekeey Team
70 KiB
Assets (4)
Versions (3) View all
2.0.0 2026-05-30
1.1.0 2026-05-28
1.0.0 2026-05-26