Toarnbeike.Dispatch.Abstractions
0.2.3
dotnet add package Toarnbeike.Dispatch.Abstractions --version 0.2.3
NuGet\Install-Package Toarnbeike.Dispatch.Abstractions -Version 0.2.3
<PackageReference Include="Toarnbeike.Dispatch.Abstractions" Version="0.2.3" />
<PackageVersion Include="Toarnbeike.Dispatch.Abstractions" Version="0.2.3" />
<PackageReference Include="Toarnbeike.Dispatch.Abstractions" />
paket add Toarnbeike.Dispatch.Abstractions --version 0.2.3
#r "nuget: Toarnbeike.Dispatch.Abstractions, 0.2.3"
#:package Toarnbeike.Dispatch.Abstractions@0.2.3
#addin nuget:?package=Toarnbeike.Dispatch.Abstractions&version=0.2.3
#tool nuget:?package=Toarnbeike.Dispatch.Abstractions&version=0.2.3
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.Resultsto 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
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Toarnbeike.Results.Abstractions (>= 2.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Toarnbeike.Dispatch.Abstractions:
| Package | Downloads |
|---|---|
|
Toarnbeike.Dispatch
lightweight dispatching framework for result driven requests and notifications |
GitHub repositories
This package is not used by any popular GitHub repositories.