private function resolveController(string $controllerName, Request $request)
    {
        if (!class_exists($controllerName)) {
            throw new RouteException("Controller class $controllerName does not exist");
        }

        $controller = $this->dependencyResolver->resolve($controllerName);

        if ($controller instanceof Controller) {
            $controller->setRequest($request);

            try {
                $controller->setViewFactory(
                    $this->dependencyResolver->resolve(IViewFactory::class)
                );
            } catch (DependencyResolutionException $ex) {
                // Don't do anything
            }

            try {
                $controller->setViewCompiler(
                    $this->dependencyResolver->resolve(ICompiler::class)
                );
            } catch (DependencyResolutionException $ex) {
                // Don't do anything
            }
        }

        return $controller;
    }