8000 Merge branch '4.4' into 5.0 · symfony/symfony-docs@5819abc · GitHub
[go: up one dir, main page]

Skip to content

Commit 5819abc

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Update service_container.rst
2 parents c3e2311 + a69fa6a commit 5819abc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

service_container.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,12 @@ This is mostly useful when you want to fetch services lazily::
850850
// ...
851851
}
852852

853-
As a best practice, you should only create *private* services, which will happen
854-
automatically. And also, you should *not* use the ``$container->get()`` method to
855-
fetch public services.
853+
As a best practice, you should only create *private* services. This allows for
854+
safe container optimizations, e.g. removing unused services. You should not use
855+
``$container->get()`` to fetch public services, as it will make it harder to
856+
make those services private later. Instead consider
857+
:ref:`injecting services <services-constructor-injection>` or using
858+
:doc:`Service Subscribers or Locators </service_container/service_subscribers_locators>`.
856859

857860
But, if you *do* need to make a service public, override the ``public`` setting:
858861

0 commit comments

Comments
 (0)
0