8000 [2.1] Method Injection · Issue #835 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[2.1] Method Injection #835
Closed
Closed
@schmittjoh

Description

@schmittjoh

This type of injection is especially useful for code that is container aware (especially controllers).

<?php

abstract class MyController
{
    /**
     * @MethodInjection
     * @return Symfony\Component\HttpFoundation\Request
     */
    abstract function getRequest();
}

The abstract method would be implemented by the service container behind the scenes:

<?php

class ConcreteController extends MyController
{
    private $container;

    public function getRequest()
    {
        return $this->container->get('request');
    }
}

The benefit is less code to write, IDE autocompletion, and no container dependency in the abstract class.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0