/// <summary>
        /// Initializes a new instance of the <see cref="CommittedAggregateEvents"/> class.
        /// </summary>
        /// <param name="eventSource">The <see cref="EventSourceId"/> that the Events were applied to.</param>
        /// <param name="aggregateRoot">The <see cref="Type"/> of the Aggregate Root that applied the Events to the Event Source.</param>
        /// <param name="events">The <see cref="CommittedAggregateEvent">events</see>.</param>
        public CommittedAggregateEvents(EventSourceId eventSource, Type aggregateRoot, IReadOnlyList <CommittedAggregateEvent> events)
        {
            EventSource   = eventSource;
            AggregateRoot = aggregateRoot;

            for (var i = 0; i < events.Count; i++)
            {
                if (i == 0)
                {
                    _nextAggregateRootVersion = events[0].AggregateRootVersion;
                }
                var @event = events[i];
                ThrowIfEventIsNull(@event);
                ThrowIfEventWasAppliedToOtherEventSource(@event);
                ThrowIfEventWasAppliedByOtherAggregateRoot(@event);
                ThrowIfAggreggateRootVersionIsOutOfOrder(@event);
                if (i > 0)
                {
                    ThrowIfEventLogVersionIsOutOfOrder(@event, events[i - 1]);
                }
                _nextAggregateRootVersion++;
            }

            _events = new NullFreeList <CommittedAggregateEvent>(events);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CommittedAggregateEvent"/> class.
 /// </summary>
 /// <param name="eventLogSequenceNumber">The event log sequence number of the Event.</param>
 /// <param name="occurred">The <see cref="DateTimeOffset" /> when the Event was committed to the Event Store.</param>
 /// <param name="eventSourceId">The <see cref="EventSourceId" /> of the Event.</param>
 /// <param name="aggregateRoot">The <see cref="Type"/> of the Aggregate Root that applied the Event to the Event Source.</param>
 /// <param name="aggregateRootVersion">The version of the <see cref="AggregateRoot"/> that applied the Event.</param>
 /// <param name="executionContext">The <see cref="ExecutionContext"/> in which the Event was committed.</param>
 /// <param name="event">An instance of the Event that was committed to the Event Store.</param>
 public CommittedAggregateEvent(
     EventLogSequenceNumber eventLogSequenceNumber,
     DateTimeOffset occurred,
     EventSourceId eventSourceId,
     Type aggregateRoot,
     AggregateRootVersion aggregateRootVersion,
     ExecutionContext executionContext,
     IEvent @event)
     : base(eventLogSequenceNumber, occurred, eventSourceId, executionContext, @event)
 {
     AggregateRoot        = aggregateRoot;
     AggregateRootVersion = aggregateRootVersion;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateRootVersionIsOutOfOrder"/> class.
 /// </summary>
 /// <param name="eventVersion">The <see cref="AggregateRootVersion"/> the Event was applied by.</param>
 /// <param name="expectedVersion">Expected <see cref="AggregateRootVersion"/>.</param>
 public AggregateRootVersionIsOutOfOrder(AggregateRootVersion eventVersion, AggregateRootVersion expectedVersion)
     : base($"Aggregate Root version is out of order. Version '{eventVersion}' from event does not match '{expectedVersion}'")
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingEventsForExpectedAggregateRootVersion"/> class.
 /// </summary>
 /// <param name="expectedVersion">The expected <see cref="AggregateRootVersion"/>.</param>
 /// <param name="actualVersion">The actual <see cref="AggregateRootVersion"/> produced by the given events.</param>
 public MissingEventsForExpectedAggregateRootVersion(AggregateRootVersion expectedVersion, AggregateRootVersion actualVersion)
     : base($"Events are missing for aggregate root. Expected version '{expectedVersion}', but provided events resulted in '{actualVersion}'.")
 {
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UncommittedAggregateEvents"/> class.
 /// </summary>
 /// <param name="eventSource">The Event Source that the uncommitted events was applied to.</param>
 /// <param name="aggregateRoot">The <see cref="Type"/> of the Aggregate Root that applied the events to the Event Source.</param>
 /// <param name="expectedAggregateRootVersion">The <see cref="AggregateRootVersion"/> of the Aggregate Root that was used to apply the rules that resulted in the Events.</param>
 public UncommittedAggregateEvents(EventSourceId eventSource, Type aggregateRoot, AggregateRootVersion expectedAggregateRootVersion)
 {
     EventSource   = eventSource;
     AggregateRoot = aggregateRoot;
     ExpectedAggregateRootVersion = expectedAggregateRootVersion;
 }