Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public RecordedEvent(RecordedEventDocument document, IJsonEventSerializer serializer, TIdentity id)
 {
     Id          = id;
     _document   = document;
     _serializer = serializer;
 }