diff --git a/service_container/remove.rst b/service_container/remove.rst new file mode 100644 index 00000000000..e8e82114299 --- /dev/null +++ b/service_container/remove.rst @@ -0,0 +1,26 @@ +.. index:: + single: Service Container; Remove Service + +How to Remove a Service +======================= + +A service can be removed from the service container if needed +(for instance in the test or a specific environment): + +.. configuration-block:: + + .. code-block:: php + + // config/services_test.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + use App\RemovedService; + + return function(ContainerConfigurator $configurator) { + $services = $configurator->services(); + + $services->remove(RemovedService::class); + }; + +Now, the container will not contain the ``App\RemovedService`` +in the test environment.