コード例 #1
0
        public async Task <bool> Commit()
        {
            await _mediatorHandler.PublishDomainEvents(this).ConfigureAwait(false);

            var success = await SaveChangesAsync() > 0;

            return(success);
        }
コード例 #2
0
        public async Task <bool> Commit()
        {
            var success = await SaveChangesAsync() > 0;

            await _mediatorHandler.PublishDomainEvents(this);

            return(success);
        }
コード例 #3
0
        public async Task <bool> Commit()
        {
            // Dispatch Domain Events collection.
            // Choices:
            // A) Right BEFORE committing data (EF SaveChanges) into the DB will make a single transaction including
            // side effects from the domain event handlers which are using the same DbContext with "InstancePerLifetimeScope" or "scoped" lifetime
            // B) Right AFTER committing data (EF SaveChanges) into the DB will make multiple transactions.
            // You will need to handle eventual consistency and compensatory actions in case of failures in any of the Handlers.
            await _mediatorHandler.PublishDomainEvents(this).ConfigureAwait(false);

            // After executing this line all the changes (from the Command Handler and Domain Event Handlers)
            // performed through the DbContext will be committed
            var success = await SaveChangesAsync() > 0;

            return(success);
        }