public static void ThrowHandlerNotFound(this IAggregateEx aggregate, object eventMessage)
        {
            string exceptionMessage =
                "Aggregate of type '{0}' raised an event of type '{1}' but not handler could be found to handle the message."
                .FormatWith(aggregate.GetType().Name, eventMessage.GetType().Name);

            throw new HandlerForDomainEventNotFoundException(exceptionMessage);
        }
        public void Snapshot(IAggregateEx aggregate, String bucket, Int32 numberOfEventsSaved)
        {
            if (SnapshotsSettings.HasOptedOut(aggregate.GetType()))
            {
                return;
            }

            var memento  = aggregate.GetSnapshot();
            var snapshot = new Snapshot(bucket, aggregate.Id.AsString(), aggregate.Version, memento);

            if (_cacheEnabled)
            {
                _cache.Set(aggregate.Id.AsString(), snapshot, _standardCachePolicy);
            }

            if (_snapshotPersistenceStrategy.ShouldSnapshot(aggregate, numberOfEventsSaved))
            {
                _persister.Persist(snapshot, aggregate.GetType().FullName);
            }
        }
예제 #3
0
        private static Dictionary <string, object> PrepareHeaders(
            IAggregateEx aggregate, Action <IDictionary <string, object> > updateHeaders)
        {
            var headers = new Dictionary <string, object>();

            headers[AggregateTypeHeader] = aggregate.GetType().FullName;
            if (updateHeaders != null)
            {
                updateHeaders(headers);
            }

            return(headers);
        }
        public virtual void Register(IAggregateEx aggregate)
        {
            if (aggregate == null)
            {
                throw new ArgumentNullException("aggregate");
            }

            this.registered = aggregate;

            // Get instance methods named Apply with one parameter returning void
            var applyMethods =
                aggregate.GetType()
                .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                .Where(
                    m => m.Name == "Apply" && m.GetParameters().Length == 1 && m.ReturnParameter.ParameterType == typeof(void))
                .Select(m => new { Method = m, MessageType = m.GetParameters().Single().ParameterType });

            foreach (var apply in applyMethods)
            {
                MethodInfo applyMethod = apply.Method;
                this.handlers.Add(apply.MessageType, m => applyMethod.Invoke(aggregate, new[] { m }));
            }
        }
예제 #5
0
 string GetBucketFor(IAggregateEx aggregate)
 {
     return(GetBucketFor(aggregate.GetType(), aggregate.Id));
 }