Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Public, private and hidden services #27293

Copy link
Copy link
Closed
@javiereguiluz

Description

@javiereguiluz
Issue body actions

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

No one assigned

    Labels

    DependencyInjectionFeatureRFCRFC = 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)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.