-
-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathEventEnvelope.cs
More file actions
35 lines (30 loc) · 905 Bytes
/
EventEnvelope.cs
File metadata and controls
35 lines (30 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Core.Events;
public record EventMetadata(
string EventId,
ulong StreamPosition,
ulong LogPosition,
PropagationContext? PropagationContext
);
public interface IEventEnvelope
{
object Data { get; }
EventMetadata Metadata { get; init; }
}
public record EventEnvelope<T>(
T Data,
EventMetadata Metadata
): IEventEnvelope where T : notnull
{
object IEventEnvelope.Data => Data;
}
public static class EventEnvelope
{
public static IEventEnvelope From(object data, EventMetadata metadata)
{
//TODO: Get rid of reflection!
var type = typeof(EventEnvelope<>).MakeGenericType(data.GetType());
return (IEventEnvelope)Activator.CreateInstance(type, data, metadata)!;
}
public static EventEnvelope<T> From<T>(T data) where T : notnull =>
new(data, new EventMetadata(Guid.CreateVersion7().ToString(), 0, 0, null));
}