Ejemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="StorableEvent" /> based on the specified domain event.
        /// </summary>
        /// <param name="domainEvent">The domain event.</param>
        public static StorableEvent ToStorableEvent(this IEvent domainEvent)
        {
            if (domainEvent == null)
            {
                throw new ArgumentNullException(nameof(domainEvent));
            }

            string eventStreamName = null;
            var    aggregateType   = domainEvent.AggregateType();

            eventStreamName = aggregateType != null
                                  ? AggregateType.EventStreamName(aggregateType)
                                  : ((dynamic)domainEvent).EventStreamName;

            return(new StorableEvent
            {
                Actor = domainEvent.Actor(),
                StreamName = eventStreamName,
                SequenceNumber = domainEvent.SequenceNumber,
                AggregateId = domainEvent.AggregateId,
                Type = domainEvent.EventName(),
                Body = JsonConvert.SerializeObject(domainEvent, Formatting.None, serializerSettings.Value),
                Timestamp = domainEvent.Timestamp,
                ETag = domainEvent.ETag,
                Id = domainEvent.AbsoluteSequenceNumber()
            });
        }