Dekiru.Hermes.Generator 0.0.1

Prefix Reserved
Suggested Alternatives

Dekiru.Hermes

Additional Details

Original package published under wrong name

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Dekiru.Hermes.Generator --version 0.0.1
                    
NuGet\Install-Package Dekiru.Hermes.Generator -Version 0.0.1
                    
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="Dekiru.Hermes.Generator" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dekiru.Hermes.Generator" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Dekiru.Hermes.Generator" />
                    
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 Dekiru.Hermes.Generator --version 0.0.1
                    
#r "nuget: Dekiru.Hermes.Generator, 0.0.1"
                    
#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 Dekiru.Hermes.Generator@0.0.1
                    
#: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=Dekiru.Hermes.Generator&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Dekiru.Hermes.Generator&version=0.0.1
                    
Install as a Cake Tool

Hermes - A messenger to the gods

Hermes is an implementation of the mediator pattern for .NET. It uses source generators to create a dispatcher for queries, commands and events.

How to use: Add Dekiru.Hermes to your project and register the generated dispatcher in your DI container. Registration is done via the AddHermes extension method on IServiceCollection. (As such, Hermes requires Microsoft.Extensions.DependencyInjection.)

The most basic usage is as follows:

[Handler]
public class MyHandler : IQueryHandler<MyQuery, MyResponse>
{
    public Task<MyResponse> Handle(MyQuery query, CancellationToken cancellationToken)
    {
        return Task.FromResult(new MyResponse());
    }
}

This will generate a Dispatch-method on the IDispatcher interface that takes a MyQuery and returns a Task<MyResponse>.

There are four types of interfaces that can be used to define handlers:

  • ICommandHander<TCommand> - Handles commands that do not return a value.
  • ICommandHandler<TCommand, TResponse> - Handles commands that return a value.
  • IQueryHandler<TQuery, TResponse> - Handles queries that return a value.
  • IEventHandler<TEvent> - Handles events that do not return a value. Multiple event handlers can be defined for the same event. Errors thrown by one handler will be ignored and the other handlers will still be executed.

Note on ICommandHandler<TCommand>: This interface is functionally identical to ICommandHandler<TCommand, Null>, where Null is a class representing a void return type. The choice between the two is primarily a matter of preference and code clarity. The Dispatch-method generated for ICommandHandler<TCommand> will return a Task, while the one for ICommandHandler<TCommand, TResponse> will return a Task<TResponse>. Handlers implementing ICommandHandler<TCommand> may be more readable in scenarios where the command does not need to return a value, as it clearly indicates that no response is expected. The developer can return Null.Task to reduce unnecessary allocations.

Beyond the handler interfaces, there's also an interface for middleware (IMiddleware<TRequest, TResponse>). Middleware can be used to add cross-cutting concerns to the dispatching process, such as logging, validation, or transaction management. Middleware is executed in the order it is registered on the handler.

[Handler]
[Middleware<MyMiddleware>]
public class MyHandler : IQueryHandler<MyQuery, MyResponse>
{
  ...
}

Middleware implements a Handle(TRequest request, Func<TRequest, CancellationToken, Task<TResponse>> next, CancellationToken cancellationToken) method. The next parameter is a delegate that invokes the next middleware in the pipeline, or the handler if there are no more middleware.

public class MyMiddleware : IMiddleware<MyQuery, MyResponse>
{
    public async Task<MyResponse> Handle(MyQuery request, Func<MyQuery, CancellationToken, Task<MyResponse>> next, CancellationToken cancellationToken)
    {
        // Do something before the handler is invoked
        var response = await next(request, cancellationToken);
        // Do something after the handler is invoked
        return response;
    }
}

As such, a middleware can modify or replace the request or response, or even short-circuit the pipeline by not calling next.

Middleware can come in two variants: Open or closed generics. Closed generics are defined for a specific request and response type, while open generics can be used for any request and response type.

public class MyMiddleware : IMiddleware<MyQuery, MyResponse> { ... } // Closed generic

public class MyOpenGenericMiddleware<TRequest, TResponse> : IMiddleware<TRequest, TResponse> { ... } // Open generic

Open middleware can be registered on the handler in three different ways:

  • [Middleware(typeof(MyOpenGenericMiddleware<,>))] - Registers the open generic middleware for the specific request and response type of the handler.
  • [Middleware<MyOpenGenericMiddleware<MyRequest, MyResponse>>] - Same as above, but using a generic type parameter.
  • [Middleware<MyOpenGenericMiddleware<_, _>>] - Same as above, but using the special _-type as a placeholder. The source generator will replace the _ with the request and response type of the handler.

Closed middleware can only be registered using the first two methods.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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