Exemplo n.º 1
0
        public ICommandHandlingResult Commit(ICommandHandlerContext context, TAggregateRoot aggregateRoot)
        {
            Contract.Assume(context?.Command != null);
            Contract.Assume(context.Metadata != null);
            Contract.Assume(aggregateRoot?.State != null);

            var command = context.Command;

            // get state tracker from aggregate root state
            var stateTracker = aggregateRoot.State.ExternalStateTracker as IEventProviderStateTracker;

            Contract.Assume(stateTracker?.Revisions != null);

            // make new transaction identity
            TransactionIdentity transactionIdentity = CreateNewTransactionIdentity();

            // create new transaction
            var transaction = new EventProviderTransaction(transactionIdentity, stateTracker.EventProvider, command, aggregateRoot, stateTracker.Revisions, context.Metadata);

            // store transaction
            _eventStore.Commit(transaction);

            // commit state tracker
            stateTracker.Commit();

            // return result
            return(CreateCommandHandlingResult(command, aggregateRoot, transactionIdentity));
        }
Exemplo n.º 2
0
        protected override void TransactionCommitted(EventProviderTransaction transaction)
        {
            // get domain events
            var domainEvents = transaction.GetDomainEvents();

            // get metadata
            var metadata = new MetaCollection(transaction.Metadata);

            // create contexts
            var contexts = domainEvents.Select(x => new DomainEventHandlerContext(x, metadata))
                           .ToArray();

            // public contexts
            _dispatcher.Publish(contexts);
        }
Exemplo n.º 3
0
        public async Task CommitAsync(EventProviderTransaction transaction)
        {
            try
            {
                await CommitTransactionAsync(transaction);

                // raise transaction committed event for any listeners
                TransactionCommitted(this, new TransactionCommittedEventArgs(transaction));
            }
            catch (AggregateRootConcurrencyException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new EventStoreException(ErrorCommittingTransaction, ex);
            }
        }
        public TransactionCommittedEventArgs(EventProviderTransaction transaction)
        {
            Contract.Requires(transaction != null);

            _transaction = transaction;
        }
Exemplo n.º 5
0
 protected abstract Task CommitTransactionAsync(EventProviderTransaction transaction);
Exemplo n.º 6
0
 protected abstract void CommitTransaction(EventProviderTransaction transaction);
 protected abstract void TransactionCommitted(EventProviderTransaction transaction);