Skip to content

[DI] add docs for new namespace option #8310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,41 @@ them will not cause the container to be rebuilt.
means that all classes are "available to be *used* as services" without needing
to be manually configured.

Multiple Service Definitions Using the Same Namespace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 3.4
The ``namespace`` option in the YAML configuration was introduced in Symfony 3.4.

If you define services using the YAML config format, the PHP namespace is used
as the key of each configuration, so you can't define different service configs
for classes under the same namespace:

.. code-block:: yaml

# app/config/services.yml
services:
App\Domain\:
resource: '../../src/Domain/*'
# ...

In order to have multiple definitions, add the ``namespace`` option and use any
unique string as the key of each service config:

.. code-block:: yaml

# app/config/services.yml
services:
command_handlers:
namespace: App\Domain\
resource: '../../src/Domain/*/CommandHandler'
tags: [command_handler]

event_subscribers:
namespace: App\Domain\
resource: '../../src/Domain/*/EventSubscriber'
tags: [event_subscriber]

.. _services-explicitly-configure-wire-services:

Explicitly Configuring Services and Arguments
Expand Down