Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 931091d

Browse files
committed
Applying changes suggested by @wouterj, adding lazy_services to components map
1 parent 50905ff commit 931091d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

components/dependency_injection/lazy_services.rst

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ In some particular cases where a very heavy service is always requested,
1414
but not always used, you may want to mark it as ``lazy`` to delay its instantiation.
1515

1616
In order to have services to lazily instantiate, you will first need to install
17-
the `ProxyManager bridge`_::
17+
the `ProxyManager bridge`_:
1818

19-
php composer.phar require symfony/proxy-manager-bridge:2.3.*
19+
.. code-block:: bash
20+
$ php composer.phar require symfony/proxy-manager-bridge:2.3.*
2021
2122
You can mark the service as ``lazy`` by manipulating its definitions:
2223

23-
2424
.. configuration-block::
2525

2626
.. code-block:: yaml
2727
2828
services:
2929
foo:
30-
class: Example\Foo
30+
class: Acme\Foo
3131
lazy: true
3232
3333
.. code-block:: xml
3434
35-
<service id="foo" class="Example\Foo" lazy="true" />
35+
<service id="foo" class="Acme\Foo" lazy="true" />
3636
3737
.. code-block:: php
3838
39-
$definition = new Definition('Example\Foo');
39+
$definition = new Definition('Acme\Foo');
4040
$definition->setLazy(true);
4141
$container->setDefinition('foo', $definition);
4242
4343
You can then require the service from the container::
4444

45-
$service = $container->get($serviceId);
45+
$service = $container->get('foo');
4646

4747
At this point the retrieved ``$service`` should be a virtual `proxy`_ with the same
4848
signature of the class representing the service.
@@ -55,10 +55,9 @@ signature of the class representing the service.
5555
The proxy gets initialized and the actual service is instantiated as soon as you interact
5656
in any way with this object.
5757

58-
Additional resources
58+
Additional Resources
5959
--------------------
6060

61-
6261
You can read more about how proxies are instantiated, generated and initialized in
6362
the `documentation of ProxyManager`_.
6463

components/map.rst.inc

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* :doc:`/components/dependency_injection/configurators`
4040
* :doc:`/components/dependency_injection/parentservices`
4141
* :doc:`/components/dependency_injection/advanced`
42+
* :doc:`/components/dependency_injection/lazy_services`
4243
* :doc:`/components/dependency_injection/workflow`
4344

4445
* **DOM Crawler**

0 commit comments

Comments
 (0)