Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f395dad

Browse filesBrowse files
Reworded and turned the sidebar into a section
1 parent 16e0cc7 commit f395dad
Copy full SHA for f395dad

File tree

1 file changed

+20
-10
lines changed
Filter options

1 file changed

+20
-10
lines changed

‎service_container.rst

Copy file name to clipboardExpand all lines: service_container.rst
+20-10Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -923,29 +923,39 @@ them will not cause the container to be rebuilt.
923923
means that all classes are "available to be *used* as services" without needing
924924
to be manually configured.
925925

926-
.. sidebar:: The ``namespace`` Option
926+
Multiple Service Definitions Using the Same Namespace
927+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
927928

928-
.. versionadded:: 3.4
929-
The ``namespace`` option was added in Symfony 3.4.
929+
.. versionadded:: 3.4
930+
The ``namespace`` option in the YAML configuration was introduced in Symfony 3.4.
930931

931-
When using the ``resource`` option in YAML, the namespace prefix can only be used once
932-
per file when defining it as the ``id``. In order to have multiple definitions in the
933-
same file with the same namespace prefix, you can use the ``namespace`` option. When
934-
this option is used, the ``id`` can be anything as long as it is unique. For example,
935-
you can define your services like this:
932+
If you define services using the YAML config format, the PHP namespace is used
933+
as the key of each configuration, so you can't define different service configs
934+
for classes under the same namespace:
935+
936+
.. code-block:: yaml
937+
938+
# app/config/services.yml
939+
services:
940+
App\Domain\:
941+
resource: '../../src/Domain/*'
942+
# ...
943+
944+
In order to have multiple definitions, add the ``namespace`` option and use any
945+
unique string as the key of each service config:
936946

937947
.. code-block:: yaml
938948
939949
# app/config/services.yml
940950
services:
941951
command_handlers:
942952
namespace: App\Domain\
943-
resource: ../../src/Domain/*/CommandHandler
953+
resource: '../../src/Domain/*/CommandHandler'
944954
tags: [command_handler]
945955
946956
event_subscribers:
947957
namespace: App\Domain\
948-
resource: ../../src/Domain/*/EventSubscriber
958+
resource: '../../src/Domain/*/EventSubscriber'
949959
tags: [event_subscriber]
950960
951961
.. _services-explicitly-configure-wire-services:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.