Toarnbeike.Dispatch 0.2.3

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

CI .NET 10 License: MIT

Toarnbeike.Dispatch

This package provides a lightweight dispatching framework for requests and notifications.

It introduces Request, RequestHandlers and Pipeline-behaviours, inspired by the Mediator design pattern.

A request is an instruction for an underlying system to do something. Either change the state of the system (Command) or request a result (Query). Each request type is handled by one specific handler, which uses the Toarnbeike.Results Result type to return either a success or a failed result.

Using the Mediator design pattern allowes for a decoupling of concerns, the request are a contract between client and server, whereas the handler is a server specific (internal) affair.

Features

  • Result driven responses - integrate directly with Toarnbeike.Results to make failures explicit.
  • Dependency injection integration - configure using the provided DI extensions.
  • Strict Command and Query segregation - Make intent clear from the definition of the request.
  • Pipeline-integration - Use pipelines with request filters to abstract cross cutting concerns away from handlers.
  • Predefined CommandResponses - Provide clear descriptions, with toaster integration, for successful commands.
  • Confirmation requering commands - Create commands that require confirmation and reformatted requests after confirmation is given.

Contents

  1. Quick start
  2. Core concepts
  3. Pipelines
  4. Responses
  5. Conclusion

Quick start

This example demonstrates the most common workflow regarding dispatching: registration, dispatching and handling the returned result.

using Toarnbeike.Requests;

public sealed record TestQuery(int Value) : IQuery<int>;									// Query that excepts an int and returns an int.

internal sealed class TestQueryHandler(IExternalDependency externalDependency) : IQueryHandler<TestQuery, int>															

// Query handler that handles the TestQuery and returns an int
{
	public async Task<Result<int>> HandleAsync(TestQuery request, CancellationToken cancellationToken = default)
	{
		return await externalDependency.IncrementByOne(request.Value);
	}
}

Clientside to work with the TestQueryHandler:

using Toarnbeike.Dispatch;
using Toarnbeike.Dispatch.DependencyInjection;

services.AddDispatching();
services.RegisterQueryHandler<TestQuery, int, TestQueryHandler>();			// starting from version 1.0, registration will be automatic using source generation.


var dispatcher = serviceProvider.GetRequiredService<IRequestDispatcher>(); // or inject via constructor.
Result<int> result = dispatcher.Dispatch(new TestQuery(42));

Console.WriteLine(result.Match(
	onSuccess: value => $"Success: returned value {value}",
	onFailure: failure => $"Something went wrong: {failure.Message}");

// output: Success: return value 43

Core concepts

WIP

Pipelines

WIP

Responses

WIP

Conclusion

Decouple requests (contract) from handler logic (implementation)

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.

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.2.3 107 4/28/2026
0.2.2 93 4/28/2026