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] Replace container injection by explicit service locators #20658

Copy link
Copy link
Closed
@nicolas-grekas

Description

@nicolas-grekas
Issue body actions

In some cases, there is no better way than injecting the container itself and use it as a service locator.
The issue then is that one can access any public service, thus it is almost impossible to track service dependencies for such code.

I'd like to propose a first class service locator concept, with mandatory and explicit dependencies declaration. Such code would have first to explicitly declare the list of services they need to get them, through a dedicated container (service locator really) that would have access to them and only them.

We could then maybe deprecate injecting the main container directly, and replace that by the possibility for such a service locator to return the "service_container" when required (though that would be a discouraged practice, but could be required for e.g container inspecting logics).

Metadata

Metadata

Assignees

No one assigned

    Labels

    DependencyInjectionRFCRFC = 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.