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 child containers  #29075

Copy link
Copy link
Closed
Closed
Copy link
@Bilge

Description

@Bilge
Issue body actions

Symfony supports the concept of just a single DI container for the entire application. If the configuration file becomes too big it can be split into separate files with includes, but it does not support isolating separate groups of services in separate containers. This is true despite the fact that the documentation explains how to create containers from scratch with configuration files.

It may be desirable in some applications to provide sub-containers that contain services of just one type for scenarios where container injection is desirable or required, but one does not want to inject the main container with all services. This is already possible by defining a ContainerInterface service that loads a custom configuration file as shown in the aforementioned documentation section. However, even though only services defined in the sub-container can be retrieved from that container, some of the services in the sub-container may have dependencies on services in the main container. For this use-case, it is important to establish a parent/child relationship between the sub-container and the main Symfony container in which the child container defers to the parent for dependencies it cannot fulfil.

Zend Framework already supports separate containers for different groupings of services, such as controllers and forms, but it's a little less trivial in Symfony due to the compiler steps. We cannot simply override get() to defer to the parent container for missing service definitions because compilation will fail before we can ever make a get() call. The compiler must be made aware of the parent container and either copy in or link to the definitions it needs from the parent according to the dependency graph.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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.