private void DiscoverCommandHandlers()
        {
            var commandHandlerTypes = typeExplorer.GetAllTypes()
                                      .Where(x => x.IsClass && !x.IsAbstract && !x.IsGenericTypeDefinition &&
                                             CommandHandlerBindingExtensions.GetCommandHandlerInterfaces(x).Length > 0)
                                      .ToArray();

            RegisterCommandHandlers(commandHandlerTypes);
            Logger.Debug($"Discovered {commandHandlerTypes.Length} command handlers: {string.Join(", ", commandHandlerTypes.Select(x => x.FullName))}");
        }
        private void RegisterCommandHandlers(IEnumerable <Type> commandHandlerTypes)
        {
            Func <ICommandBus> commandBusLambda = () => kernel.Get <ILocalCommandBus>();

            foreach (Type commandHandlerType in commandHandlerTypes)
            {
                kernel.BindCommandHandler(commandHandlerType);

                var interfaces = CommandHandlerBindingExtensions
                                 .GetCommandHandlerInterfaces(commandHandlerType);

                foreach (var handlerInterface in interfaces)
                {
                    var commandType = handlerInterface.GetGenericArguments()[0];
                    if (!commandRouter.HasRoute(commandType))
                    {
                        commandRouter.AddRoute(commandType, commandBusLambda);
                    }
                }
            }
        }