Skip to content

Update service_container.rst #13620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ This is mostly useful when you want to fetch services lazily::

As a best practice, you should only create *private* services, which will happen
automatically. And also, you should *not* use the ``$container->get()`` method to
fetch public services.
fetch private services.
Comment on lines 861 to +863
Copy link
Contributor

@dbrumann dbrumann May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

As a best practice, you should only create *private* services.
This allows for safe container optimizations, e.g. removing
unused services. You should not use ``$container->get()``
to fetch public services, as it will make it harder to make those
services private later. Instead consider :ref:`injecting services <_services-constructor-injection>`
or using :doc:`Service Subscribers or Locators </service_container/service_subscribers_locators>`.

I prefer this over the old text, because it not only tells you not to do it, but also why and what alternatives you have. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, really better especially because it tells you why you should do that.


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

Expand Down