Closed
Description
Description
In the past, services were public or private (I'm ignoring "synthetic" services and other edge cases):
- Public: these are the services that you can use in your app. Also, you can
$this->get()
them in controllers. - Private: don't use these services in your own code! These are "internal" services created by Symfony or third-party bundles. In modern Symfony versions you can't get them with
$this->get()
because they have random service IDs.
Also, private services don't appear on debug:container
. It makes sense.
Problem
In recent Symfony versions we made all services private by default. In my opinion, the problem is that we don't really want to make services private. In fact, those services are used in your app, so their "nature" is to be public. We make them private so you can't do $this->get()
to get them (and to unlock some performance improvements).
Proposal
What if we do this:
- Remove all features to get services with
$this->get()
in controllers and commands and force to always inject services. This is a BC break, only possible in Symfony 5. - Restore the previous behavior: all services are public, unless you make them private for some reason. Private services don't appear on
debug:container
- Remove the concept of "hidden services", which are now "private services" again.
Metadata
Metadata
Assignees
Labels
RFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)