private void ApplyEvent <TIdentity, TAggregate>( TAggregate aggregate, AggregateConfiguration <TIdentity, TAggregate> configuration, RecordedEventDocument document ) where TAggregate : Aggregate <TIdentity, TAggregate> { var applicators = configuration.Applicators; if (!applicators.TryGetValue(document.EventType, out var applicator)) { throw new InvalidOperationException($"Unexpected recorded event type: {document.EventType}"); } applicator(aggregate, _serializer, document.Data ?? Array.Empty <byte>()); var recordableEvent = new RecordableEvent(document.EventNumber); aggregate.Record(recordableEvent); }
private RecordedEventDocument RecordedEvent( string category, string stream, IPendingEvent pendingEvent, long eventNumber ) { var e = new RecordedEventDocument(); e.Stream = stream; e.EventId = pendingEvent.Id; e.EventType = pendingEvent.Type; e.EventNumber = eventNumber; e.Created = UtcNow; e.Data = pendingEvent.Data(_serializer); e.Metadata = pendingEvent.Metadata(_metadataFactory, _serializer); e.Category = category; return(e); }
private TAggregate ConstructAggregate <TIdentity, TAggregate>( TIdentity id, AggregateConfiguration <TIdentity, TAggregate> configuration, RecordedEventDocument document ) where TAggregate : Aggregate <TIdentity, TAggregate> { var constructors = configuration.Constructors; if (!constructors.TryGetValue(document.EventType, out var constructor)) { throw new InvalidOperationException($"Unrecognized construction event type: {document.EventType}"); } var aggregate = constructor(id, _serializer, document.Data ?? Array.Empty <byte>()); var recordableEvent = new RecordableEvent(document.EventNumber); aggregate.Record(recordableEvent); return(aggregate); }
public RecordedEvent(RecordedEventDocument document, IJsonEventSerializer serializer, TIdentity id) { Id = id; _document = document; _serializer = serializer; }