Table of Contents

Class IntegrationEventExtensions

Namespace
Savvyio.EventDriven
Assembly
Savvyio.EventDriven.dll

Extension methods for the IIntegrationEvent interface.

public static class IntegrationEventExtensions
Inheritance
IntegrationEventExtensions

Examples

Use IntegrationEventExtensions to read the event ID, timestamp, and member type from an integration event's metadata before publishing it to another subsystem.

using System;
using Savvyio.EventDriven;

namespace ExampleApp;

public sealed class IntegrationEventExtensionsExample
{
    public (string EventId, DateTime Timestamp, string MemberType) Describe()
    {
        var e = new MemberCreatedEvent("MEM-42");
        e.Metadata[Savvyio.MetadataDictionary.MemberType] = typeof(MemberCreatedEvent).FullName;

        string eventId = e.GetEventId<MemberCreatedEvent>();
        DateTime timestamp = e.GetTimestamp<MemberCreatedEvent>();
        string memberType = e.GetMemberType<MemberCreatedEvent>();
        Console.WriteLine($"Event {eventId} at {timestamp:O}, type: {memberType}");
        return (eventId, timestamp, memberType);
    }
}

public sealed record MemberCreatedEvent(string MemberId) : IntegrationEvent;

Methods

GetEventId<T>(T)

Gets the string representation of the event identifier from the request.

public static string GetEventId<T>(this T request) where T : IIntegrationEvent

Parameters

request T

The IIntegrationEvent to extend.

Returns

string

The string representation of the event identifier from the request.

Type Parameters

T

The model that implements the IIntegrationEvent interface.

GetMemberType<T>(T)

Gets the string representation of the type from the request.

public static string GetMemberType<T>(this T request) where T : IIntegrationEvent

Parameters

request T

The IIntegrationEvent to extend.

Returns

string

The string representation of the type from the request.

Type Parameters

T

The model that implements the IIntegrationEvent interface.

GetTimestamp<T>(T)

Gets the DateTime value of the timestamp from the request.

public static DateTime GetTimestamp<T>(this T request) where T : IIntegrationEvent

Parameters

request T

The IIntegrationEvent to extend.

Returns

DateTime

The DateTime value of the timestamp from the request.

Type Parameters

T

The model that implements the IIntegrationEvent interface.