Hi folks, I know its quite hard to deal with an EventStream. Its not that best to detect if a specific event is part of the stream or if one event happened earlier than an other. So that's the reason I've created an Extension for the DomainEventStream. It helps you to get the right information about your stream.
DomainEventStream
it self allows only to append events...of course. But if you want to get the events use the function Events()
var events = await domainEventStream.Events();
The variable domainEventStream
is set up by the Function Binding, btw.
Now you have all Events in your hand as list of DomainEvent
. This list is the basement for the Extension.
Of course you can use all the fantastic LinQ functions, but I added some special functions to the list.
Ist not because of I don't like LinQ. No no, ist because of readability
All Events have to implement the Interface
IDomainEvent
or could inherit fromDomainEvent
.
var allEvents = events.Get<T>().All();
Gets all Events of Type T
.
var someEvents = events.Get<T>().Any().Where([expression]);
Gets all Events of Type T
which fits to expression or gets an empty list.
var singleEvent = events.Get<T>().Where([expression]);
Gets a single Event of Type T
which fits to the expression or returns null if not.
var firstEvent = events.Get<T>().First().Where([expression]);
Gets the first Event of Type T
which fits to expression or returns null if no Event will be found.
var lastEvent = events.Get<T>().Last().Where([expression]);
Gets the last event of Type T
which fits to expression or returns null if no Event will be found.
var theOnlyOne = events.Get<T>().TheOnlyOne();
Get the only one Event of Type T
or if not exists it returns null.
Check by order means how to find out if an event is happen earlier or later than an other event.
var happendEarlier = events.Event<T1>().HappenedEarlierThan<T2>();
Checks if any Event of Type T1
happened earlier in the history than an Event of Type T2
.
var happenedEarlier = events.Event<T1>()
.Where([expression])
.HappenedEarlierThan<T2>()
.Where([expression]);
It checks if Event of Type T1
happened earlier in the history than Event of Type T2
.
To get true both events have to exist. The comparison is between the first of Type T1
and the last of Type T2
.
If any of the types exists many times maybe the result becomes a wrong value.
var happendLater = events.Event<T1>().HappenedLaterThan<T2>();
Checks if any Event of Type T1
happened later in the history than an Event of Type T2
.
var happenedLater = events.Event<T1>()
.Where([expression])
.HappenedLaterThan<T2>()
.Where([expression]);
It checks if Event of Type T1
happened later in the history than Event of Type T2
.
To get true both events have to exist. The comparison is between the last of Type T1
and the first of Type T2
.
If any of the types exists many times maybe the result becomes a wrong value.
var exists = events.Event<T>().Exists();
Checks if an Event of Type T
exists in the stream.
var exists = events.Event<T>().Where([expression]).Exists();
Checks if an Event of Type T filtered by an expression exists in the stream.