File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ Dependency Injection
43
43
* :ref: `TaggedLocator <service-subscribers-locators_defining-service-locator >`
44
44
* :ref: `Target <autowiring-multiple-implementations-same-type >`
45
45
* :ref: `When <service-container_limiting-to-env >`
46
+ * :ref: `WhenNot <service-container_limiting-to-env >`
46
47
47
48
EventDispatcher
48
49
~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -260,6 +260,32 @@ as a service in some environments::
260
260
// ...
261
261
}
262
262
263
+ If you want to exclude a service from being registered in a specific
264
+ environment, you can use the ``#[WhenNot] `` attribute::
265
+
266
+ use Symfony\Component\DependencyInjection\Attribute\WhenNot;
267
+
268
+ // SomeClass is registered in all environments except "dev"
269
+
270
+ #[WhenNot(env: 'dev')]
271
+ class SomeClass
272
+ {
273
+ // ...
274
+ }
275
+
276
+ // you can apply more than one WhenNot attribute to the same class
277
+
278
+ #[WhenNot(env: 'dev')]
279
+ #[WhenNot(env: 'test')]
280
+ class AnotherClass
281
+ {
282
+ // ...
283
+ }
284
+
285
+ .. versionadded :: 7.2
286
+
287
+ The ``#[WhenNot] `` attribute was introduced in Symfony 7.2.
288
+
263
289
.. _services-constructor-injection :
264
290
265
291
Injecting Services/Config into a Service
You can’t perform that action at this time.
0 commit comments