public void Handle(ICommand command)
        {
            IEventStream eventStream = _eventStore.Load(command.AggregateId);
            Type         type        = GetTargetType(command);
            IAmAggregate root        = CreateAggregate(type);

            if (root == null)
            {
                throw new InvalidOperationException("Could not get instance for aggreagate from command.");
            }

            foreach (var @event in eventStream)
            {
                root.Process(@event);
                //Process(root, @event);
            }

            var events = Handle(root, command);

            if (events != null && events.Any())
            {
                var tag = EventTags.GetOrCreateIfNotExists(type);
                _eventStore.Store(tag, command.AggregateId, eventStream.Version, events);
            }
        }
        private IEnumerable <IEvent> Handle(IAmAggregate root, ICommand command)
        {
            var type       = root.GetType();
            var paramType  = command.GetType();
            var methodInfo = type.GetMethods().Where(m => m.Name == "Handle" && m.GetParameters()[0].ParameterType == paramType).SingleOrDefault();

            if (methodInfo != null)
            {
                return(methodInfo.Invoke(root, new[] { command }) as IEnumerable <IEvent>);
            }
            throw new InvalidOperationException("No 'Handle' method on aggregate to handle " + paramType.Name);
        }
 private IEnumerable<IEvent> Handle(IAmAggregate root, ICommand command)
 {
     var type = root.GetType();
     var paramType = command.GetType();
     var methodInfo = type.GetMethods().Where(m => m.Name == "Handle" && m.GetParameters()[0].ParameterType == paramType).SingleOrDefault();
     if (methodInfo != null)
     {
         return methodInfo.Invoke(root, new[] { command }) as IEnumerable<IEvent>;
     }
     throw new InvalidOperationException("No 'Handle' method on aggregate to handle " + paramType.Name);
 }