Skip to content

Console Command doc in 3.4 advocates using the Service Container #8713

Closed
@alsciende

Description

@alsciende

In Symfony 3.4, services are private by default and the general tendency is to move away from using the Service Container, and use the Dependency Injection instead, whenever possible.

The documentation of Console Commands, though, still advocates extending ContainerAwareCommand and getting the container to get any service the command is relying on.

It would be interesting to precede this with a section explaining how to inject services directly into the command, like what is done in the Controller documentation page (https://symfony.com/doc/current/controller.html#fetching-services-as-controller-arguments). I suppose the recommended way is to use the autowiring of __construct, so this could be a side note in the section that says "your command classes are automatically registered as services.".

Metadata

Metadata

Assignees

No one assigned

    Labels

    hasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions