Esempio n. 1
0
        private DomainEventEnvelope GetDomainEventWrapperFromEvent(TEventSet @event)
        {
            var domainEvent = _serializer.Deserialize <IDomainEvent>(@event.Payload);

            return(new DomainEventEnvelope(@event.EventId, @event.AggregateId, @event.Sequence, @event.AggregateVersion,
                                           domainEvent));
        }
Esempio n. 2
0
        public Tuple <TAggregateRoot, int> GetLatestSnapshot(Guid aggregateId)
        {
            var lastEventSequence = 0;

            var snapshotSet = Context.Set <TAggregateMemento>();
            var snapshot    =
                snapshotSet.AsNoTracking()
                .OrderByDescending(s => s.LastEventSequence)
                .FirstOrDefault(x => x.AggregateRootId == aggregateId);

            if (snapshot == null)
            {
                return(null);
            }

            lastEventSequence = snapshot.LastEventSequence;

            var stringSerializer = new JsonObjectSerializer();
            var aggregateRoot    = stringSerializer.Deserialize <TAggregateRoot>(snapshot.Payload);

            return(new Tuple <TAggregateRoot, int>(aggregateRoot, lastEventSequence));
        }