How to add metadata in Event entity of Eventflow

152 Views Asked by At

I am working on a web solution that uses .NET 6 framework as backend with EventFlow (Event-sourcing & CQRS). All of my events are store in the table EventEntity :

EventEntity table

I would like to add additional information in the Metadata attribute. I read the documentation but I don't understand about how to do it :

The documentation :

Documentation

The Metadata attribute is in JSON format :

Metadata in json

Any help would be appreciated

1

There are 1 best solutions below

0
On BEST ANSWER

I've found the anwser.

By the use of IMetadataProvider

Example :


public static readonly string UserNameKey = "username";
public static readonly string UserAccountKey = "useraccount";

public IEnumerable<KeyValuePair<string, string>> ProvideMetadata<TAggregate, TIdentity>(TIdentity id, IAggregateEvent aggregateEvent, IMetadata metadata)
   where TAggregate : IAggregateRoot<TIdentity>
   where TIdentity : IIdentity
{
   var userAccount = this.identityService.GetUserIdentity();
   var userName = this.identityService.GetUserName();
   yield return new KeyValuePair<string, string>(UserNameKey, userName);
   yield return new KeyValuePair<string, string>(UserAccountKey, userAccount);
}