Exemplo n.º 1
0
        public static IApplyEventsInternal From <TState>(IApplyEvents <TState> publicApplier)
        {
            var stateType = typeof(TState);

            return(new FunctionalInternalApplier((s, e) => publicApplier.Apply((TState)s, e),
                                                 (s, e) => s == stateType && publicApplier.CanApplyEvent(e)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applies all <see cref="Commit.Events"/> to the specified <paramref name="aggregate"/> instance.
        /// </summary>
        /// <param name="commit">The <see cref="Commit"/> to be applied to the specified <paramref name="aggregate"/>.</param>
        /// <param name="aggregate">The <see cref="Aggregate"/> instance for which the commit is to be applied.</param>
        private void ApplyCommitToAggregate(Commit commit, Aggregate aggregate)
        {
            var expectedVersion = aggregate.Version + 1;

            if (commit.Version != expectedVersion)
            {
                throw new InvalidOperationException(Exceptions.MissingAggregateCommits.FormatWith(expectedVersion, commit.Version));
            }

            aggregate.Version = commit.Version;
            foreach (var e in commit.Events)
            {
                using (new EventContext(aggregate.Id, commit.Headers, e))
                    aggregateUpdater.Apply(e, aggregate);
            }
        }