From 41670b00f61b93c4071a50f0540fb8cf16209d73 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 29 Nov 2015 23:19:23 -0500 Subject: [PATCH] [#5922] Tweaks thanks to reviewers --- cookbook/map.rst.inc | 1 + cookbook/service_container/shared.rst | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cookbook/map.rst.inc b/cookbook/map.rst.inc index 7917f2e1a54..73587ee5d47 100644 --- a/cookbook/map.rst.inc +++ b/cookbook/map.rst.inc @@ -193,6 +193,7 @@ * :doc:`/cookbook/service_container/index` + * :doc:`/cookbook/service_container/shared` * :doc:`/cookbook/service_container/scopes` * :doc:`/cookbook/service_container/compiler_passes` * (Event Dispatcher) :doc:`/cookbook/event_dispatcher/event_listener` diff --git a/cookbook/service_container/shared.rst b/cookbook/service_container/shared.rst index 205afd7028d..92844d1958f 100644 --- a/cookbook/service_container/shared.rst +++ b/cookbook/service_container/shared.rst @@ -1,7 +1,7 @@ .. index:: single: Service Container; Shared Services -How to Define Not Shared Services +How to Define Non Shared Services ================================= .. versionadded:: 2.8 @@ -10,7 +10,7 @@ How to Define Not Shared Services In the service container, all services are shared by default. This means that each time you retrieve the service, you'll get the *same* instance. This is -often the behaviour you want, but in some cases, you might want to always get a +often the behavior you want, but in some cases, you might want to always get a *new* instance. In order to always get a new instance, set the ``shared`` setting to ``false`` @@ -20,6 +20,7 @@ in your service definition: .. code-block:: yaml + # app/config/services.yml services: app.some_not_shared_service: class: ... @@ -28,16 +29,20 @@ in your service definition: .. code-block:: xml + .. code-block:: php + use Symfony\Component\DependencyInjection\Definition; + + // app/config/services.php $definition = new Definition('...'); $definition->setShared(false); $container->setDefinition('app.some_not_shared_service', $definition); Now, whenever you call ``$container->get('app.some_not_shared_service')`` or -inject this service, you'll recieve a new instance. +inject this service, you'll receive a new instance.