Skip to content

[DependencyInjection] Suggestion for autowiring parameters #22755

@zmitic

Description

@zmitic
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3

When services are autowired, parameter values still needs to be declared in definition like:

    app.my_service:
        class: AppBundle\Service\MyService
        arguments: 
            - $clientHostParameter: "%client_host%"

What about guessing them based on variable name? For example:

class MyService
{
    public function __construct(TwigEngine $twigEngine, $clientHostParameter)
    {
        //...
    }

So if variable ends with word parameter, S3 would tableize clientHost, look for parameter client_host and inject it.

An example taken from Symfony Flex demo would then become:

class RecipeLoader
{
    public function __construct(LoggerInterface $logger, $kernelDebugParameter)
    {
        //...
    }

What do you think?


Sorry if someone posted this idea before.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions