File tree 1 file changed +9
-5
lines changed
components/dependency_injection
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,14 @@ argument for another service.
20
20
21
21
.. _inlined-private-services :
22
22
23
- .. note ::
23
+ Since a container is not able to detect if a service is retrieved from inside
24
+ the container or the outside, a private service may still be retrieved using
25
+ the ``get() `` method.
24
26
25
- If you use a private service as an argument to only one other service,
26
- this will result in an inlined instantiation (e.g. ``new PrivateFooBar() ``)
27
- inside this other service, making it publicly unavailable at runtime.
27
+ What makes private services special, is that they are converted from services
28
+ to inlined instantiation (e.g. ``new PrivateThing() ``) when they are only
29
+ injected once, to increase the container performance. This means that you can
30
+ never be sure if a private service exists in the container.
28
31
29
32
Simply said: A service will be private when you do not want to access it
30
33
directly from your code.
@@ -60,7 +63,8 @@ Here is an example:
60
63
$definition->setPublic(false);
61
64
$container->setDefinition('foo', $definition);
62
65
63
- Now that the service is private, you *cannot * call::
66
+ Now that the service is private, you *should not * call (should not means, this
67
+ *might * fail, see the explaination above)::
64
68
65
69
$container->get('foo');
66
70
You can’t perform that action at this time.
0 commit comments