@@ -158,6 +158,7 @@ hold the kernel. Now it looks like this::
158
158
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
159
159
{
160
160
$loader->load(__DIR__.'/../config/framework.yaml');
161
+ $loader->load(__DIR__.'/../config/services.yaml');
161
162
162
163
// configure WebProfilerBundle only if the bundle is enabled
163
164
if (isset($this->bundles['WebProfilerBundle'])) {
@@ -199,6 +200,61 @@ Before continuing, run this command to add support for the new dependencies:
199
200
200
201
$ composer require symfony/yaml symfony/twig-bundle symfony/web-profiler-bundle doctrine/annotations
201
202
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
+
202
258
Unlike the previous kernel, this loads an external ``config/framework.yaml `` file,
203
259
because the configuration started to get bigger:
204
260
0 commit comments