title: Symfony 4 not autowiring dynamic route controllers
body: <p>Symfony version: <code>4.1.3</code></p>
  
  <p>I have an application which loads dynamic routes based on configuration by virtue of a route loader service, but it appears that Symfony 4 is not autowiring the dynamic route controllers.</p>
  
  <p>I am using the standard Symfony 4 application services.yaml file:</p>
  
  <p><strong>/config/services.yaml</strong></p>
  
  <pre><code>parameters:
  services:
     # default configuration for services in *this* file
    _defaults:
       autowire: true      # Automatically injects dependencies in your services.
       autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
       public: false       # Allows optimizing the container by removing unused services; this also means
                           # fetching services directly from the container via $container-&gt;get() won't work.
                           # The best practice is to be explicit about your dependencies anyway.
  
    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    Application\Web\:
      resource: '../src/*'
      exclude: '../src/{Search/Model,Entity,Migrations,Tests,Kernel.php}'
  
    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    Application\Web\Controller\:
      resource: '../src/Controller'
      tags: ['controller.service_arguments']
  </code></pre>
  
  <p><strong>Route Loader:</strong> <code>src/Component/RouteLoader.php</code></p>
  
  <pre><code>&lt;?php
  
  namespace Application\Web\Component;
  
  use Application\Symfony\Bundle\ConfigBundle\ReaderInterface;
  use Symfony\Component\Routing\Route;
  use Symfony\Component\Routing\RouteCollection;
  
  /**
   * Class RouteLoader
   * @package Application\Web\Component
   */
  class RouteLoader
  {
      /**
       * @var ReaderInterface
       */
      private $configurationReader;
  
      public function __construct(ReaderInterface $configurationReader)
      {
          $this-&gt;configurationReader = $configurationReader;
      }
  
      public function load(): RouteCollection
      {
          $routes = new RouteCollection();
          foreach ($this-&gt;configurationReader-&gt;find('category_navigation') as $label =&gt; $configuration) {
              $slug = strtolower($label);
              $route = new Route(
                  $configuration['url'],
                  [
                      '_controller' =&gt; [$configuration['controller'], 'dispatch'],
                      'categories_slug' =&gt; $slug,
                      'category_label' =&gt; $label,
                      'page_title' =&gt; $configuration['page_title'] ?? null,
                      'page_description' =&gt; $configuration['page_description'] ?? null,
                  ],
                  [],
                  [],
                  '',
                  [],
                  ['GET']
              );
              $routes-&gt;add($slug . '.home', $route);
          }
  
          return $routes;
      }
  }
  </code></pre>
  
  <p><strong>Controller constructor:</strong> <code>src/Controller/Page.php</code></p>
  
  <pre><code>&lt;?php
  
  namespace Application\Web\Controller;
  
  //.... other class code
  
  public function __construct(
      ClientInterface $client,
      ReaderInterface $configurationReader,
      \Twig_Environment $twigEnvironment,
      ContentSearcher $contentSearcher,
      Environment $environment,
      TokenStorageInterface $tokenStorage,
      UrlGeneratorInterface $urlGenerator
  )
  </code></pre>
  
  <p>When I try to load the page, Symfony whines with the following error:</p>
  
  <pre><code>Controller "\Application\Web\Controller\Page" has required constructor arguments and does not exist in the container. Did you forget to define such a service?
  </code></pre>
  
  <p>However, when I define the route directly in the <code>config/routes.yaml</code> file, the controller is autowired in style with no issues!</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Is this a limitation of Symfony's autowiring capability, i.e. not supported for dynamic route controllers?</li>
  <li>Is there something that I'm missing when it comes to defining the routes that will make the autowiring work?</li>
  <li>Have I potentially identified a bug? </li>
  </ul>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT: Stack traces</strong></p>
  
  <pre><code>InvalidArgumentException:
  Controller "\Application\Web\Controller\Page" has required constructor arguments and does not exist in the container. Did you forget to define such a service?
  
    at vendor/symfony/http-kernel/Controller/ContainerControllerResolver.php:62
    at Symfony\Component\HttpKernel\Controller\ContainerControllerResolver-&gt;instantiateController('\\Application\\Web\\Controller\\Page')
   (vendor/symfony/framework-bundle/Controller/ControllerResolver.php:54)
    at Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver-&gt;instantiateController('\\Application\\Web\\Controller\\Page')
   (vendor/symfony/http-kernel/Controller/ControllerResolver.php:49)
    at Symfony\Component\HttpKernel\Controller\ControllerResolver-&gt;getController(object(Request))
   (vendor/symfony/http-kernel/Controller/TraceableControllerResolver.php:38)
    at Symfony\Component\HttpKernel\Controller\TraceableControllerResolver-&gt;getController(object(Request))
   (vendor/symfony/http-kernel/HttpKernel.php:132)
    at Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(object(Request), 1)
   (vendor/symfony/http-kernel/HttpKernel.php:66)
    at Symfony\Component\HttpKernel\HttpKernel-&gt;handle(object(Request), 1, true)
   (vendor/symfony/http-kernel/Kernel.php:188)
    at Symfony\Component\HttpKernel\Kernel-&gt;handle(object(Request))
   (public/index.php:37)
  
  
   ArgumentCountError:
  Too few arguments to function Application\Web\Controller\Base::__construct(), 0 passed in /var/www/html/vendor/symfony/http-kernel/Controller/ControllerResolver.php on line 133 and exactly 7 expected
  
    at src/Controller/Base.php:55
    at Application\Web\Controller\Base-&gt;__construct()
   (vendor/symfony/http-kernel/Controller/ControllerResolver.php:133)
    at Symfony\Component\HttpKernel\Controller\ControllerResolver-&gt;instantiateController('\\Application\\Web\\Controller\\Page')
   (vendor/symfony/http-kernel/Controller/ContainerControllerResolver.php:55)
    at Symfony\Component\HttpKernel\Controller\ContainerControllerResolver-&gt;instantiateController('\\Application\\Web\\Controller\\Page')
   (vendor/symfony/framework-bundle/Controller/ControllerResolver.php:54)
    at Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver-&gt;instantiateController('\\Application\\Web\\Controller\\Page')
   (vendor/symfony/http-kernel/Controller/ControllerResolver.php:49)
    at Symfony\Component\HttpKernel\Controller\ControllerResolver-&gt;getController(object(Request))
   (vendor/symfony/http-kernel/Controller/TraceableControllerResolver.php:38)
    at Symfony\Component\HttpKernel\Controller\TraceableControllerResolver-&gt;getController(object(Request))
   (vendor/symfony/http-kernel/HttpKernel.php:132)
    at Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(object(Request), 1)
   (vendor/symfony/http-kernel/HttpKernel.php:66)
    at Symfony\Component\HttpKernel\HttpKernel-&gt;handle(object(Request), 1, true)
   (vendor/symfony/http-kernel/Kernel.php:188)
    at Symfony\Component\HttpKernel\Kernel-&gt;handle(object(Request))
   (public/index.php:37)
  </code></pre>