@@ -223,6 +223,50 @@ each time you ask for it.
223
223
it. Later, you'll learn how to :ref: `import many services at once
224
224
<service-psr4-loader>` with resource.
225
225
226
+ If some files or directories in your project should not become services, you
227
+ can exclude them using the ``exclude `` option:
228
+
229
+ .. configuration-block ::
230
+
231
+ .. code-block :: yaml
232
+
233
+ # config/services.yaml
234
+ services :
235
+ # ...
236
+ App\ :
237
+ resource : ' ../src/'
238
+ exclude :
239
+ - ' ../src/SomeDirectory/'
240
+ - ' ../src/AnotherDirectory/'
241
+ - ' ../src/SomeFile.php'
242
+
243
+ .. code-block :: xml
244
+
245
+ <!-- config/services.xml -->
246
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
247
+ <container xmlns =" http://symfony.com/schema/dic/services"
248
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
249
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
250
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
251
+
252
+ <services >
253
+ <prototype namespace =" App\" resource =" ../src/" exclude =" ../src/{SomeDirectory,AnotherDirectory,Kernel.php}" />
254
+ <!-- ... -->
255
+ </services >
256
+ </container >
257
+
258
+ .. code-block :: php
259
+
260
+ // config/services.php
261
+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
262
+
263
+ return function(ContainerConfigurator $container): void {
264
+ // ...
265
+
266
+ $services->load('App\\', '../src/')
267
+ ->exclude('../src/{SomeDirectory,AnotherDirectory,Kernel.php}');
268
+ };
269
+
226
270
If you'd prefer to manually wire your service, you can
227
271
:ref: `use explicit configuration <services-explicitly-configure-wire-services >`.
228
272
0 commit comments