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 70ec5df

Browse filesBrowse files
committed
[DI] add docs for new namespace option
1 parent d410c46 commit 70ec5df
Copy full SHA for 70ec5df

File tree

1 file changed

+28
-0
lines changed
Filter options

1 file changed

+28
-0
lines changed

‎service_container.rst

Copy file name to clipboardExpand all lines: service_container.rst
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,34 @@ 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+
The namespace Option
927+
--------------------
928+
929+
.. versionadded:: 3.4
930+
The ``namespace`` option was added in Symfony 3.4.
931+
932+
When using the ``resource`` option in YAML, the namespace prefix can only be used once
933+
per file when defining it as the ``id``. In order to have multiple definitions in the
934+
same file with the same namespace prefix, you can use the ``namespace`` option. When
935+
this option is used, the ``id`` can be anything as long as it is unique. For example,
936+
you can define your services like this:
937+
938+
.. configuration-block::
939+
940+
.. code-block:: yaml
941+
942+
# app/config/services.yml
943+
services:
944+
command_handlers:
945+
namespace: App\Domain\
946+
resource: ../../src/Domain/*/CommandHandler
947+
tags: [command_handler]
948+
949+
event_subscribers:
950+
namespace: App\Domain\
951+
resource: ../../src/Domain/*/EventSubscriber
952+
tags: [event_subscriber]
953+
926954
.. _services-explicitly-configure-wire-services:
927955

928956
Explicitly Configuring Services and Arguments

0 commit comments

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