private void CallCommandOnAggregate(ICommand command, AggregateBase aggregateBase)
 {
     if (aggregateBase != null)
     {
         aggregateBase.CallMethod(CommandHandlerMethodName, command);
     }
     else
     {
         throw new AggregateNotFoundException();
     }
 }
 /// <summary>
 ///     Publishes the updated version of the aggregate we are working with to a publisher. This could be a queue or a database writer in low volume scenarios.
 /// </summary>
 private static void PublishUpdatedAggregate(AggregateBase instance)
 {
     IAggregateUpdatePublisher publisher = Core.Instance.AggregateUpdatePublisher;
     if (publisher != null)
     {
         Core.Instance.AggregateUpdatePublisher.PublishUpdate(instance);
     }
 }
        private void InvokeEvent(AggregateBase instance, IEvent @event)
        {
            Type eventType = @event.GetType();

            MethodInfo eventHandlerMethod =
                instance.GetType()
                        .Methods()
                        .FirstOrDefault(mi => mi.GetParameters().Any(i => i.ParameterType == eventType));

            if (eventHandlerMethod != null)
            {
                eventHandlerMethod.Invoke(instance, new object[] {@event});

                if (!_aggregateLoading)
                {
                    PublishUpdatedAggregate(instance);
                    UpdateAggregateCache(instance);
                }
            }
        }
 /// <summary>
 ///     This updates the aggregate in the cache, if used.
 /// </summary>
 /// <param name="instance"></param>
 private static void UpdateAggregateCache(AggregateBase instance)
 {
     if (Core.Instance.UseCaching && Core.Instance.Cache != null)
     {
         Core.Instance.Cache.Cache(instance);
     }
 }