@@ -923,29 +923,39 @@ them will not cause the container to be rebuilt.
923
923
means that all classes are "available to be *used * as services" without needing
924
924
to be manually configured.
925
925
926
- .. sidebar :: The ``namespace`` Option
926
+ Multiple Service Definitions Using the Same Namespace
927
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
927
928
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.
930
931
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:
936
946
937
947
.. code-block :: yaml
938
948
939
949
# app/config/services.yml
940
950
services :
941
951
command_handlers :
942
952
namespace : App\Domain\
943
- resource : ../../src/Domain/*/CommandHandler
953
+ resource : ' ../../src/Domain/*/CommandHandler'
944
954
tags : [command_handler]
945
955
946
956
event_subscribers :
947
957
namespace : App\Domain\
948
- resource : ../../src/Domain/*/EventSubscriber
958
+ resource : ' ../../src/Domain/*/EventSubscriber'
949
959
tags : [event_subscriber]
950
960
951
961
.. _services-explicitly-configure-wire-services :
0 commit comments