예제 #1
0
        private static void UpdateStream(IAggregateRoot stream, Guid commandId)
        {
            var notCommited = stream.NotCommitedChanges().ToList();

            if (!notCommited.Any())
            {
                return;
            }

            var versionCnt = stream.Metadata.Version;

            foreach (var bEvent in notCommited)
            {
                var aggregateType = stream.GetType().FullName;
                var new_version   = ++versionCnt;

                bEvent.EventId  = $"{stream.Metadata.AggregateId}_{new_version}";
                bEvent.Metadata = new SourcedEventMetadata
                {
                    Version       = new_version,
                    CommandId     = commandId,
                    AggregateId   = stream.Metadata.AggregateId,
                    AggregateType = aggregateType,
                    Date          = DateTime.UtcNow
                };
            }
        }
예제 #2
0
        private static void UpdateAggregateVersion(IAggregateRoot stream)
        {
            var notCommited = stream.NotCommitedChanges().ToList();

            if (!notCommited.Any())
            {
                return;
            }

            stream.Metadata.Version = notCommited.Last().Metadata.Version;
        }
예제 #3
0
        private async Task SendEvents(IAggregateRoot stream, ICommand command)
        {
            var notCommited = stream.NotCommitedChanges().ToList();

            if (!notCommited.Any())
            {
                return;
            }

            if (eventSender != null)
            {
                foreach (var se in notCommited)
                {
                    await eventSender.Send(se, command);
                }
            }
        }