Skip to content

Commit

Permalink
[symfony#5922] Tweaks thanks to reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Nov 30, 2015
1 parent 93a08f3 commit 41670b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions cookbook/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 8 additions & 3 deletions cookbook/service_container/shared.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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``
Expand All @@ -20,6 +20,7 @@ in your service definition:

.. code-block:: yaml
# app/config/services.yml
services:
app.some_not_shared_service:
class: ...
Expand All @@ -28,16 +29,20 @@ in your service definition:
.. code-block:: xml
<!-- app/config/services.xml -->
<services>
<service id="app.some_not_shared_service" class="..." shared="false" />
</services>
.. 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.

0 comments on commit 41670b0

Please sign in to comment.