Table of Contents

TracedDomainEventExtensions Class

Definition

Namespace
Savvyio.Domain.EventSourcing
Assemblies
Savvyio.Domain.EventSourcing.dll
Source
src/Savvyio.Domain.EventSourcing/TracedDomainEventExtensions.cs

Extension methods for the ITracedDomainEvent interface.

public static class TracedDomainEventExtensions
Inheritance
TracedDomainEventExtensions

Examples

Use TracedDomainEventExtensions to set and read back the aggregate version and member type on a ITracedDomainEvent. Call SetAggregateVersion when recording the event and GetAggregateVersion when replaying the aggregate stream.

using System;
using Savvyio.Domain.EventSourcing;

namespace ExampleApp;

public sealed class TracedDomainEventExtensionsExample
{
    public (long Version, string MemberType) StampAndRead()
    {
        var e = new AccountStateCapturedEvent("ACC-42")
            .SetAggregateVersion(7);
        e.Metadata[Savvyio.MetadataDictionary.MemberType] = typeof(AccountStateCapturedEvent).FullName;

        long version = e.GetAggregateVersion<AccountStateCapturedEvent>();
        string memberType = e.GetMemberType<AccountStateCapturedEvent>();
        Console.WriteLine($"Version: {version}, MemberType: {memberType}");
        return (version, memberType);
    }
}

public sealed record AccountStateCapturedEvent(string AccountId) : Savvyio.Request, ITracedDomainEvent;

Methods

Name Description
GetAggregateVersion<T>(T)

Gets the aggregate version from the request.

GetMemberType<T>(T)

Gets the string representation of the type from the request.

SetAggregateVersion<T>(T, long)

Assigns a new version to the request.