@@ -138,10 +138,28 @@ as in the above example, the ``App\`` definition creates services for classes
138
138
found in ``../src/* ``. If your imported file defines services for those classes
139
139
too, they will be overridden.
140
140
141
- A possible solution for this is to add the classes and/or directories of the
142
- imported files in the ``exclude `` option of the ``App\ `` definition. Another
143
- solution is to not use imports and add the service definitions in the same file,
144
- but after the ``App\ `` definition to override it.
141
+ There are exactly three possible solutions in order services not to get overriden:
142
+ 1. Include the file with ``App\ `` statement in the ``imports `` as the first element.
143
+ In order to the fact that the ``imports `` statement not override existing services, it checks if the services exists,
144
+ also take into account that the last element of the ``imports `` has the highest priority and will be executed first,
145
+ having included ``App\ `` as a first element of ``imports `` (with the lowest priority) it will be imported in the end.
146
+ And being the last import element it will only add not existing services in the container.
147
+ 2. Include the path to the service in the ``exclude `` section.
148
+ 3. Write service definitions down the ``App\ `` statement to override it
149
+
150
+ It's recommended to use the 1st approach to define services in the container
151
+ Using the first approach the whole ``services.yaml `` file will look the foolowing way:
152
+
153
+ ..configuration-block ::
154
+ ..code-block ::yaml
155
+ ###> imports are loaded first (imports not overrides existing services) ###
156
+ imports:
157
+ - resource: 'services_yaml/resource_services.yaml' # PRIORITY 1 (last) (contains App\ with resource statement)
158
+ - resource: 'services_yaml/services/' # PRIORITY 2
159
+ - resource: 'services_yaml/parameters/' # PRIORITY 3 (first)
160
+
161
+ ###> then services.yaml (what below overrides imports) ###
162
+ ###>... it's better to use only imports
145
163
146
164
..include ::/components/dependency_injection/_imports-parameters-note.rst.inc
147
165