As per posts passim, the event instance holds the business meaningful data about the event that occurred. These properties can be read by projections in order to build up some view of the current state of an aggregate.
However, there are also aspects we need to store for any given event that do not have a business meaningful aspect: the identity of the event which uniquely identifies the particular instance and the context of the event which is additional logging or status information we want to store for diagnostic purposes only.
In order to keep the event processing as pure as possible, I want to keep this extra information outside the event data itself (therefore making it unavailable to a projection so developers don't inadvertently use context information in a business process).
To do this, I introduce an interface that defines how an event is wrapped in its identity:
Public Interface IEventIdentity(Of TAggregate As CQRSAzure.EventSourcing.IAggregationIdentifier)
Function GetAggregateIdentifier() As String
ReadOnly Property Sequence As UInteger
ReadOnly Property EventInstance As IEvent(Of TAggregate)
End Interface
This in turn can be wrapped inside a interface that provides the additional context information:
Public Interface IEventContext
Inherits IEventInstance
ReadOnly Property Who As String
ReadOnly Property Timestamp As Date
ReadOnly Property Source As String
ReadOnly Property SequenceNumber As Long
ReadOnly Property Commentary As String
End Interface
Public Interface IEventContext(Of TAggregationKey)
Inherits IEventContext
Inherits IEventInstance(Of TAggregationKey)
End Interface
The reason that these are kept as interfaces is that the actual implementation of the backing store for the event may affect how the instance and context data are stored - for example in an SQL database, you would probably have the identity and context information as separate fields in the table(s) whereas for a file based solution, the identity part might be derived from the filename the event is stored in and the offset in that file could be the event sequence number.
CodeProject