public void Add(IDomainEvent domainEvent, int sequenceId)
        {
            if (GetSequenceId(domainEvent.GetAggregateId()) >= sequenceId)
            {
                throw new SequenceAlreadyStoredException();
            }

            var line = JsonConvert.SerializeObject(domainEvent, _jsonSerializerSettings);

            File.AppendAllLines(GetFileName(domainEvent.GetAggregateId().Value), new[] { line });
        }
Beispiel #2
0
        //public void Add(EventsWrapper eventsWrapper)
        //{
        //    if (_dictionary.ContainsKey(eventsWrapper.AggregateId))
        //    {
        //        var domainEvents = _dictionary[eventsWrapper.AggregateId];
        //        var sequenceId = domainEvents.Count;
        //        if (sequenceId >= eventsWrapper.SequenceId) throw new SequenceAlreadyStoredException();

        //        domainEvents.AddRange(eventsWrapper.DomainEvents);
        //        return;
        //    }

        //    foreach (var domainEvent in eventsWrapper.DomainEvents)
        //    {
        //        _dictionary.Add(eventsWrapper.AggregateId, new List<IDomainEvent> { domainEvent });
        //    }
        //}

        public void Add(IDomainEvent domainEvent, int sequenceId)
        {
            IAggregateId aggregateId = domainEvent.GetAggregateId();

            if (_dictionary.ContainsKey(aggregateId))
            {
                var domainEvents = _dictionary[aggregateId];
                if (domainEvents.Count >= sequenceId)
                {
                    throw new SequenceAlreadyStoredException();
                }

                domainEvents.Add(domainEvent);
                return;
            }

            _dictionary.Add(aggregateId, new List <IDomainEvent> {
                domainEvent
            });
        }