-
Notifications
You must be signed in to change notification settings - Fork 2
Events
There are two "levels" of event types in RdbmsEventStore: one of them are your own POCO events, that require no ceremony or special interfaces other than the possibility to serialize and deserialize them (and you can control the serialization mechanism, too). The other is the wrapping implementation of IEvent
, which carries metadata such as the StreamId
and Timestamp
as well as a payload: your POCO event.
The default IEvent<TStream>
has the following shape:
public IEventMetadata<out TStreamId>
{
TStreamId StreamId { get; }
DateTimeOffset Timestamp { get; }
long Version { get; }
}
public IEvent<out TStreamId> : IEventMetadata<TStreamId>
{
Type Type { get; }
object Payload { get; }
}
(There's also a default implementation Event<TStreamId>
that you can use.)
If you want some extra metadata, e.g. the user ID of the user who triggered the event, you can create your own event interfaces and implementations including that.
public interface IUserAwareEventMetadata : IEventMetadata<long> // choosing long for stream ids
{
long TriggeredBy { get; }
}
public interface IUserAwareEvent : IEvent<long>, IUserAwareMetaData { }
public class UserAwareEvent : IUserAwareEvent, Event<long>
{
long TriggeredBy { get; set; }
}
Finally, you should be aware that there are mutable versions of these interfaces as well (e.g. IMutableEvent<TStreamId>
and IMutableEventMetadata<TStreamId>
) that you probably want to extend to ease instantiation of events.