예제 #1
0
        public void AddEvent(IEntityDomainEvent domainEvent)
        {
            this.CheckIfNotDisposed(nameof(AddEvent));

            var entityDomainEvents = this.domainEvents.GetOrAdd(new EntityIdentifier(domainEvent.Entity), e => new ConcurrentBag <IEntityDomainEvent>());

            entityDomainEvents.Add(domainEvent);
        }
예제 #2
0
        public async Task Publish(IEntityDomainEvent domainEvent, bool onTransactionCommit = false)
        {
            if (onTransactionCommit)
            {
                var domainEventsScope = this.domainEventScope.Current;
                if (domainEventsScope == null)
                {
                    throw new DomainException($"Cannot publish domain event on transaction commit: current {nameof(IEntityDomainEventTransactionScope)} does not exist.");
                }

                domainEventsScope.AddEvent(domainEvent);
            }
            else
            {
                await this.Publish(domainEvent);
            }
        }