Skip to content

Commit 903189f

Browse files
committed
minor #8310 [DI] add docs for new namespace option (kbond, javiereguiluz)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] add docs for new namespace option | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to? | 3.4 | Fixed tickets? | symfony/symfony#23991 Commits ------- f395dad Reworded and turned the sidebar into a section 16e0cc7 [DI] add docs for new namespace option
1 parent 1d93bf4 commit 903189f

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

service_container.rst

+37-2
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ made. To do that, you create a new class::
371371
->addPart(
372372
'Someone just updated the site. We told them: '.$happyMessage
373373
);
374-
374+
375375
return $this->mailer->send($message) > 0;
376376
}
377377
}
@@ -389,7 +389,7 @@ you can use the service immediately::
389389
if ($siteUpdateManager->notifyOfSiteUpdate()) {
390390
$this->addFlash('success', 'Notification mail was sent successfully.');
391391
}
392-
392+
393393
// ...
394394
}
395395

@@ -954,6 +954,41 @@ them will not cause the container to be rebuilt.
954954
means that all classes are "available to be *used* as services" without needing
955955
to be manually configured.
956956

957+
Multiple Service Definitions Using the Same Namespace
958+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
959+
960+
.. versionadded:: 3.4
961+
The ``namespace`` option in the YAML configuration was introduced in Symfony 3.4.
962+
963+
If you define services using the YAML config format, the PHP namespace is used
964+
as the key of each configuration, so you can't define different service configs
965+
for classes under the same namespace:
966+
967+
.. code-block:: yaml
968+
969+
# app/config/services.yml
970+
services:
971+
App\Domain\:
972+
resource: '../../src/Domain/*'
973+
# ...
974+
975+
In order to have multiple definitions, add the ``namespace`` option and use any
976+
unique string as the key of each service config:
977+
978+
.. code-block:: yaml
979+
980+
# app/config/services.yml
981+
services:
982+
command_handlers:
983+
namespace: App\Domain\
984+
resource: '../../src/Domain/*/CommandHandler'
985+
tags: [command_handler]
986+
987+
event_subscribers:
988+
namespace: App\Domain\
989+
resource: '../../src/Domain/*/EventSubscriber'
990+
tags: [event_subscriber]
991+
957992
.. _services-explicitly-configure-wire-services:
958993

959994
Explicitly Configuring Services and Arguments

0 commit comments

Comments
 (0)