Class TracedDomainEventExtensions
- Namespace
- Savvyio.Domain.EventSourcing
- Assembly
- Savvyio.Domain.EventSourcing.dll
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
GetAggregateVersion<T>(T)
Gets the aggregate version from the request.
public static long GetAggregateVersion<T>(this T request) where T : ITracedDomainEvent
Parameters
requestTThe ITracedDomainEvent to extend.
Returns
- long
The version of the associated ITracedAggregateRoot<TKey>.
Type Parameters
TThe model that implements the ITracedDomainEvent interface.
GetMemberType<T>(T)
Gets the string representation of the type from the request.
public static string GetMemberType<T>(this T request) where T : ITracedDomainEvent
Parameters
requestTThe ITracedDomainEvent to extend.
Returns
- string
The string representation of the type from the
request.
Type Parameters
TThe model that implements the ITracedDomainEvent interface.
SetAggregateVersion<T>(T, long)
Assigns a new version to the request.
public static T SetAggregateVersion<T>(this T request, long version) where T : ITracedDomainEvent
Parameters
requestTThe ITracedDomainEvent to extend.
versionlongThe aggregate version of the model.
Returns
- T
A reference to
requestafter the operation has completed.
Type Parameters
TThe model that implements the ITracedDomainEvent interface.