Table of Contents

HandlerFactory Class

Definition

Namespace
Savvyio
Assemblies
Savvyio.Core.dll
Source
src/Savvyio.Core/HandlerFactory.cs

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

Name Description
CreateFireForget<TRequest>(Action<IFireForgetRegistry<TRequest>>)

Creates an instance of a Fire-and-Forget/In-Only MEP activator responsible of invoking delegates that handles TRequest.

CreateRequestReply<TRequest>(Action<IRequestReplyRegistry<TRequest>>)

Creates an instance of a Request-Reply/In-Out MEP activator responsible of invoking delegates that handles TRequest.