private static void CreateActionDescriptors(TypeInfo commandHandler, HandlerMethodsMapping methodsMapping)
        {
            var commandHandlerDescriptor = new HandlerParentObjectDescriptor(commandHandler);
            var actionHandlers           = GetHandlerForCommandHandler(commandHandler);

            foreach (var actionHandler in actionHandlers)
            {
                var(commandType, descriptor) = CreateActionDescriptor(actionHandler, commandHandlerDescriptor);
                commandHandlerDescriptor.AddActionDescriptor(descriptor);
                methodsMapping.Add(commandType, descriptor);
            }
        }
 public HandlerMethodDescriptor(Type commandType, MethodInfo action, HandlerParentObjectDescriptor handlerParentObjectDescriptor)
 {
     Action      = action;
     CommandType = commandType;
     HandlerParentObjectDescriptor = handlerParentObjectDescriptor;
 }
        private static (Type, HandlerMethodDescriptor) CreateActionDescriptor(MethodInfo method, HandlerParentObjectDescriptor handlerParentObjectDescriptor)
        {
            var parameters = method.GetParameters();

            if (parameters.Length != 1)
            {
                throw new InvalidOperationException("An command handler must have only one parameter, this parameter being the command");
            }
            if (!method.ReturnType.IsAssignableFrom(typeof(Task)))
            {
                throw new InvalidOperationException("An command handler must have return an ICommandActionResult");
            }

            var commandType = parameters.First().ParameterType;

            var descriptor = new HandlerMethodDescriptor(commandType, method, handlerParentObjectDescriptor);

            return(commandType, descriptor);
        }