title: Symfony 5 micro application with MicroKernelTrait throws error "controller has no container set"
body: <p>I'm trying to build a micro application with Symfony 5, the single-file approach works, but the advanced example using Twig, etc. does not.</p>
  
  <p>I built a test-project following the exact description as published here: <a href="https://symfony.com/doc/current/configuration/micro_kernel_trait.html" rel="nofollow noreferrer">https://symfony.com/doc/current/configuration/micro_kernel_trait.html</a>, I have the same directory structure and the same file contents as in the example:</p>
  
  <p><a href="https://i.stack.imgur.com/VyCVt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VyCVt.png" alt="enter image description here"></a></p>
  
  <p>This is the index.php to get the application started:</p>
  
  <pre><code>// public/index.php
  use App\Kernel;
  use Doctrine\Common\Annotations\AnnotationRegistry;
  use Symfony\Component\HttpFoundation\Request;
  
  $loader = require __DIR__.'/../vendor/autoload.php';
  // auto-load annotations
  AnnotationRegistry::registerLoader([$loader, 'loadClass']);
  
  $kernel = new Kernel('dev', true);
  $request = Request::createFromGlobals();
  $response = $kernel-&gt;handle($request);
  $response-&gt;send();
  $kernel-&gt;terminate($request, $response);
  </code></pre>
  
  <p>And this is the MicroController with the (sample) action:</p>
  
  <pre><code>namespace App\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  use Symfony\Component\Routing\Annotation\Route;
  
  class MicroController extends AbstractController
  {
      /**
       * @Route("/random/{limit}")
       */
      public function randomNumber($limit)
      {
          $number = random_int(0, $limit);
  
          return $this-&gt;render('micro/random.html.twig', [
              'number' =&gt; $number,
          ]);
      }
  }
  </code></pre>
  
  <p>The method "configureContainer" in Kernel.php is called and runs without error:</p>
  
  <pre><code>protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
  {
      $loader-&gt;load(__DIR__.'/../config/framework.yaml');
  
      // configure WebProfilerBundle only if the bundle is enabled
      if (isset($this-&gt;bundles['WebProfilerBundle'])) {
          $c-&gt;loadFromExtension('web_profiler', [
              'toolbar' =&gt; true,
              'intercept_redirects' =&gt; false,
          ]);
      }
  }
  </code></pre>
  
  <p>but still the project does not run, calling a valid route (e.g. "/random/10" as in the example) gives me the error: "<strong>"App\Controller\MicroController" has no container set, did you forget to define it as a service subscriber?</strong>"</p>
  
  <p>my composer.json looks like this:</p>
  
  <pre><code>"doctrine/annotations": "^1.8",
  "symfony/config": "^5.0",
  "symfony/dependency-injection": "^5.0",
  "symfony/framework-bundle": "^5.0",
  "symfony/http-foundation": "^5.0",
  "symfony/http-kernel": "^5.0",
  "symfony/routing": "^5.0",
  "symfony/twig-bundle": "^5.0",
  "symfony/web-profiler-bundle": "^5.0",
  "symfony/yaml": "^5.0",
  </code></pre>
  
  <p>What am I missing? Any hint is appreciated.</p>