Skip to content

Navigation Menu

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] Autowire arguments that are container parameters #21699

Copy link
Copy link
Closed
@javiereguiluz

Description

@javiereguiluz
Issue body actions
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3

These days we're updating the Symfony Demo app to use the new service configuration proposed for Symfony 3.3. See https://github.com/symfony/symfony-demo/pull/483/files

One of the things I like the least is this config:

services:
    AppBundle\Twig\AppExtension:
        $locales: '%app_locales%'

    AppBundle\EventListener\RedirectToPreferredLocaleSubscriber:
        $locales: '%app_locales%'

    AppBundle\EventListener\CommentNotificationSubscriber:
        $sender: '%app.notifications.email_sender%'

Having to create that boring config just to pass some container parameters destroys the purpose of this new config being RAD, etc.

Proposal

Would it make any sense to "autowire the parameters"?

Before

class AppExtension extends \Twig_Extension
{
    // ...

    public function __construct(Markdown $parser, $locales)
    {
        // ...
    }

    // ...
}
services:
    AppBundle\Twig\AppExtension:
        $locales: '%app_locales%'

After

class AppExtension extends \Twig_Extension
{
    // ...

    public function __construct(Markdown $parser, $locales = '%app_locales%')
    {
        // ...
    }

    // ...
}

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.