Class HandlerFactory
- Namespace
- Savvyio
- Assembly
- Savvyio.Core.dll
Provides access to factory methods for creating and configuring generic handlers that supports MEP.
public static class HandlerFactory
- Inheritance
-
HandlerFactory
Examples
HandlerFactory creates the activator delegates used internally by Savvy I/O handlers to bind request types to handler methods. Use HandlerFactory.CreateFireForget<TRequest> to build fire-and-forget delegates or CreateRequestReply<TRequest, TResponse> for delegates that return a response.
using System;
using System.Threading.Tasks;
using Savvyio;
using Savvyio.Handlers;
namespace ExampleApp;
public sealed class HandlerFactoryExample
{
public async Task DispatchAsync()
{
var notifications = HandlerFactory.CreateFireForget<IRequest>(
r => r.Register<CreateOrderCommand>(cmd => Console.WriteLine("Processing: " + cmd.OrderId)));
var command = new CreateOrderCommand("ORD-42");
notifications.TryInvoke(command);
await notifications.TryInvokeAsync(command).ConfigureAwait(false);
}
}
public sealed record CreateOrderCommand(string OrderId) : Request;
Methods
CreateFireForget<TRequest>(Action<IFireForgetRegistry<TRequest>>)
Creates an instance of a Fire-and-Forget/In-Only MEP activator responsible of invoking delegates that handles TRequest.
public static IFireForgetActivator<TRequest> CreateFireForget<TRequest>(Action<IFireForgetRegistry<TRequest>> handlerRegistrar)
Parameters
handlerRegistrarAction<IFireForgetRegistry<TRequest>>The delegate responsible for registering delegates of type
TRequest.
Returns
- IFireForgetActivator<TRequest>
An implementation of the IFireForgetActivator<TRequest> interface responsible of invoking delegates that handles
TRequest.
Type Parameters
TRequestThe type of the model to handle.
CreateRequestReply<TRequest>(Action<IRequestReplyRegistry<TRequest>>)
Creates an instance of a Request-Reply/In-Out MEP activator responsible of invoking delegates that handles TRequest.
public static IRequestReplyActivator<TRequest> CreateRequestReply<TRequest>(Action<IRequestReplyRegistry<TRequest>> handlerRegistrar)
Parameters
handlerRegistrarAction<IRequestReplyRegistry<TRequest>>The delegate responsible for registering delegates of type
TRequest.
Returns
- IRequestReplyActivator<TRequest>
An implementation of the IRequestReplyActivator<TRequest> interface responsible of invoking delegates that handles
TRequest.
Type Parameters
TRequestThe type of the model to handle.