Exemplo n.º 1
0
 public void ApplyChange(IDomainEvent <TId> domainEvent, bool isFromHistory = false)
 {
     lock (_events)
     {
         InnerApply(domainEvent);
         if (!isFromHistory)
         {
             _events.Enqueue(domainEvent);
             domainEvent.SetVersion(Version + 1);
         }
         if (Version + 1 != domainEvent.Version)
         {
             throw new AggregateVersioningException(
                       $"DomainEvent({domainEvent.GetType().Name}) version {domainEvent.Version} is not valid, next version should be {Version + 1}");
         }
         Version++;
     }
 }
Exemplo n.º 2
0
        private void ApplyChange(IDomainEvent e, bool isNew)
        {
            var applyMethodInfo = GetType().GetMethod("Apply", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { e.GetType() }, null);

            if (applyMethodInfo == null)
            {
                throw new InvalidOperationException($"Aggregate '{GetType().Name}' can't apply '{e.GetType().Name}' event type.");
            }

            applyMethodInfo.Invoke(this, new object[] { e });

            IncrementedVersion();
            if (isNew)
            {
                e.SetVersion(Version);
                e.SetTimestamp(UtcNow);
                _domainEvents.Add(e);
            }
        }