Пример #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));
        }
Пример #2
0
        public EventStoreCommandHandlingResult(Guid commandId, AggregateRootIdentity aggregateRootIdentity, TransactionIdentity transactionIdentity)
            : base(commandId, aggregateRootIdentity)
        {
            Contract.Requires(commandId != Guid.Empty);
            Contract.Requires(aggregateRootIdentity != null);
            Contract.Requires(transactionIdentity != null);

            TransactionIdentity = transactionIdentity;
        }
Пример #3
0
        private TransactionIdentity CreateNewTransactionIdentity()
        {
            Contract.Ensures(Contract.Result <TransactionIdentity>() != null);

            var transactionGuid = _guidGenerator.Create();

            Contract.Assume(transactionGuid != Guid.Empty);

            var transactionIdentity = new TransactionIdentity(transactionGuid);

            return(transactionIdentity);
        }
Пример #4
0
        public EventProviderTransaction(TransactionIdentity identity, IEventProvider eventProvider, ICommand command, IAggregateRoot aggregateRoot, IReadOnlyCollection <EventStreamRevision> revisions, IReadOnlyCollection <Meta> metadata)
        {
            Contract.Requires(command != null);
            Contract.Requires(aggregateRoot != null);
            Contract.Requires(eventProvider != null);
            Contract.Requires(revisions != null);
            Contract.Requires(metadata != null);

            Contract.Assume(identity != null);

            _identity      = identity;
            _command       = command;
            _eventProvider = eventProvider;
            _revisions     = revisions;
            _descriptor    = new EventProviderDescriptor(aggregateRoot);
            _metadata      = metadata;
        }
Пример #5
0
        private static ICommandHandlingResult CreateCommandHandlingResult(ICommand command, TAggregateRoot aggregateRoot, TransactionIdentity transactionIdentity)
        {
            Contract.Requires(aggregateRoot != null);
            Contract.Requires(command != null);
            Contract.Requires(transactionIdentity != null);
            Contract.Ensures(Contract.Result <ICommandHandlingResult>() != null);

            var aggregateRootIdentity = aggregateRoot.Identity;

            Contract.Assume(aggregateRootIdentity != null);

            var commandId = command.CommandId;

            Contract.Assume(commandId != Guid.Empty);

            return(new EventStoreCommandHandlingResult(commandId, aggregateRootIdentity, transactionIdentity));
        }