@@ -54,9 +54,7 @@ Next, create an ``index.php`` file that defines the kernel class and executes it
5454
5555 protected function configureRoutes(RoutingConfigurator $routes)
5656 {
57- // kernel is a service that points to this class
58- // optional 3rd argument is the route name
59- $routes->add('/random/{limit}', 'kernel::randomNumber');
57+ $routes->add('random_number', '/random/{limit}')->controller([$this, 'randomNumber']);
6058 }
6159
6260 public function randomNumber($limit)
@@ -151,7 +149,7 @@ hold the kernel. Now it looks like this::
151149 ];
152150
153151 if ($this->getEnvironment() == 'dev') {
154- $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
152+ $bundles[] = new\ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
155153 }
156154
157155 return $bundles;
@@ -160,6 +158,7 @@ hold the kernel. Now it looks like this::
160158 protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
161159 {
162160 $loader->load(__DIR__.'/../config/framework.yaml');
161+ $loader->load(__DIR__.'/../config/services.yaml');
163162
164163 // configure WebProfilerBundle only if the bundle is enabled
165164 if (isset($this->bundles['WebProfilerBundle'])) {
@@ -201,6 +200,61 @@ Before continuing, run this command to add support for the new dependencies:
201200
202201 $ composer require symfony/yaml symfony/twig-bundle symfony/web-profiler-bundle doctrine/annotations
203202
203+ You need add the following service configuration, which is the default config for a new project:
204+
205+ ..configuration-block ::
206+
207+ ..code-block ::yaml
208+
209+ # config/services.yaml
210+ services :
211+ # default configuration for services in *this* file
212+ _defaults :
213+ autowire :true # Automatically injects dependencies in your services.
214+ autoconfigure :true # Automatically registers your services as commands, event subscribers, etc.
215+
216+ # makes classes in src/ available to be used as services
217+ # this creates a service per class whose id is the fully-qualified class name
218+ App\ :
219+ resource :' ../src/*'
220+
221+ ..code-block ::xml
222+
223+ <!-- config/services.xml-->
224+ <?xml version =" 1.0" encoding =" UTF-8" ?>
225+ <container xmlns =" http://symfony.com/schema/dic/services"
226+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
227+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
228+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
229+
230+ <services >
231+ <!-- Default configuration for services in *this* file-->
232+ <defaults autowire =" true" autoconfigure =" true" />
233+
234+ <!-- makes classes in src/ available to be used as services-->
235+ <!-- this creates a service per class whose id is the fully-qualified class name-->
236+ <prototype namespace =" App\" resource =" ../src/*" />
237+ </services >
238+ </container >
239+
240+ ..code-block ::php
241+
242+ // config/services.php
243+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
244+
245+ return function(ContainerConfigurator $configurator) {
246+ // default configuration for services in *this* file
247+ $services = $configurator->services()
248+ ->defaults()
249+ ->autowire() // Automatically injects dependencies in your services.
250+ ->autoconfigure() // Automatically registers your services as commands, event subscribers, etc.
251+ ;
252+
253+ // makes classes in src/ available to be used as services
254+ // this creates a service per class whose id is the fully-qualified class name
255+ $services->load('App\\', '../src/*');
256+ };
257+
204258 Unlike the previous kernel, this loads an external ``config/framework.yaml `` file,
205259because the configuration started to get bigger:
206260