Skip to content

[DI][Proposal] Annotation-based autowiring #25810

Closed
@andrewtch

Description

@andrewtch
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 4.0

I propose to introduce @Autowire annotation that will inject services into private / protected properties (the same way as Doctrine does with entities) instead of passing them to constructor. This can work like so:

class Service
{
    /**
     * @Autowire
     * @var Symfony\Component\Routing\RouterInterface
     */
    protected $router;
}

This would mimic Spring's @Autowired annotation and allow simpler DI if necessary, especially when inheriting services (on a small performance cost of reflection call, which is to be measured). Of course, container - injection should stay.

Was this behaviour discussed before?

See: http://www.baeldung.com/spring-autowire

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