Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy