Immediate.Handlers
Creating handlers
Handlers can be created by using the following code:
This will automatically generate a new class, GetUsersQuery.Handler
, which encapsulates the following:
- attaching any behaviors defined for all queries in the assembly
- using a class to receive any DI services, such as
UsersService
Any consumer can now do the following:
For Command handlers, use a ValueTask
, and Immediate.Handlers will insert a return type
of ValueTuple
to your handler automatically.
In case your project layout does not allow direct for references between consumer and handler, the handler will also be
registered as an IHandler<TRequest, Response>
.
IServiceCollection
Registering with Immediate.Handlers supports Microsoft.Extensions.DependencyInjection.Abstractions
directly. To register handlers with DI, simply add the following to your Program.cs
:
This registers all classes in the assembly marked with [Handler]
.