Skip to content

Commit 6ffdd07

Browse files
committed
feature #7021 [ServiceContainer] Remove implementation details of private services (lemoinem)
This PR was merged into the master branch. Discussion ---------- [ServiceContainer] Remove implementation details of private services Since symfony/symfony#19708, getting private services through `Container::get()` is deprecated in the cases where it worked up to now, and this will removed in 4.0. The ways a container optimizes private services instanciation are not useful information anymore and is confusing to some (see #6959). I removed the mentions of these implementations details to make the documentation clearer. Commits ------- a529157 [ServiceContainer] Remove any references to the implementation details of private services
2 parents 37066fa + a529157 commit 6ffdd07

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

service_container/alias_private.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ above.
2222

2323
.. _inlined-private-services:
2424

25-
In these cases, to get a minor performance boost, you can set the service
26-
to be *not* public (i.e. private):
25+
In these cases, to get a minor performance boost and ensure the service will not
26+
be retrieved directly from the container, you can set the service to be *not*
27+
public (i.e. private):
2728

2829
.. configuration-block::
2930

@@ -54,18 +55,19 @@ to be *not* public (i.e. private):
5455
$definition->setPublic(false);
5556
$container->setDefinition('foo', $definition);
5657
57-
What makes private services special is that, if they are only injected once,
58-
they are converted from services to inlined instantiations (e.g. ``new PrivateThing()``).
59-
This increases the container's performance.
58+
What makes private services special is that, since the container knows that the
59+
service will never be requested from outside, it can optimize whether and how it
60+
is instanciated. This increases the container's performance.
6061

6162
Now that the service is private, you *should not* fetch the service directly
6263
from the container::
6364

6465
$container->get('foo');
6566

66-
This *may or may not work*, depending on if the service could be inlined.
67-
Simply said: A service can be marked as private if you do not want to access
68-
it directly from your code.
67+
This *may or may not work*, depending on how the container as optimized the
68+
service instanciation and, even in the cases where it works, is
69+
deprecated. Simply said: A service can be marked as private if you do not want
70+
to access it directly from your code.
6971

7072
However, if a service has been marked as private, you can still alias it
7173
(see below) to access this service (via the alias).

0 commit comments

Comments
 (0)