Table of Contents

Class IntegrationEventDispatcher

Namespace
Savvyio.EventDriven
Assembly
Savvyio.EventDriven.dll

Provides a default implementation of of the IIntegrationEventDispatcher interface.

public class IntegrationEventDispatcher : FireForgetDispatcher, IIntegrationEventDispatcher, IDispatcher
Inheritance
IntegrationEventDispatcher
Implements
Inherited Members

Examples

IntegrationEventDispatcher routes an integration event to all registered IIntegrationEventHandler implementations through a ServiceLocator. Register the handler and create the dispatcher with a service locator that resolves handlers by their service type.

using System.Collections.Generic;
using Savvyio;
using Savvyio.Dispatchers;
using Savvyio.EventDriven;
using Savvyio.Handlers;

namespace ExampleApp;

public sealed class IntegrationEventDispatcherExample
{
    public IReadOnlyCollection<string> Publish()
    {
        var handler = new AccountCreatedHandler();
        var locator = new ServiceLocator(serviceType =>
            serviceType == typeof(IIntegrationEventHandler) ? new object[] { handler } : new object[0]);
        var dispatcher = new IntegrationEventDispatcher(locator);
        dispatcher.Publish(new AccountCreatedEvent("ACC-42", "alice@example.com"));
        return handler.NotifiedEmails;
    }
}

public sealed class AccountCreatedHandler : IIntegrationEventHandler
{
    public List<string> NotifiedEmails { get; } = new();

    public IFireForgetActivator<IIntegrationEvent> Delegates =>
        HandlerFactory.CreateFireForget<IIntegrationEvent>(r =>
            r.Register<AccountCreatedEvent>(e => NotifiedEmails.Add(e.Email)));
}

public sealed record AccountCreatedEvent(string AccountId, string Email) : Request, IIntegrationEvent;

Constructors

IntegrationEventDispatcher(IServiceLocator)

Initializes a new instance of the IntegrationEventDispatcher class.

public IntegrationEventDispatcher(IServiceLocator serviceLocator)

Parameters

serviceLocator IServiceLocator

The provider of service implementations.

Methods

Publish(IIntegrationEvent)

Publishes the specified request using Fire-and-Forget/In-Only MEP.

public void Publish(IIntegrationEvent request)

Parameters

request IIntegrationEvent

The IIntegrationEvent to publish.

PublishAsync(IIntegrationEvent, Action<AsyncOptions>)

Publishes the specified request asynchronous using Fire-and-Forget/In-Only MEP.

public Task PublishAsync(IIntegrationEvent request, Action<AsyncOptions> setup = null)

Parameters

request IIntegrationEvent

The IIntegrationEvent to publish.

setup Action<AsyncOptions>

The AsyncOptions which may be configured.

Returns

Task

A Task that represents the asynchronous operation.

See Also