Turn autowire & autoconfigure ON/OFF globally

Created on 3 June 2024, 7 months ago
Updated 2 July 2024, 6 months ago

Problem/Motivation

On a project we have tons of custom modules. I would like to have autowire and autoconfigure enabled by default, w/o needing to edit all *.services.yml ? Probably I can add a compiler pass but I wonder if there’s a better way

Proposed resolution

Maybe a container parameter that we can switch from settings.php or something that makes it simple to enable/disable

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 1 hour ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @claudiu.cristea
  • Merge request !8278Resolve #3452304 "Global auto" β†’ (Open) created by claudiu.cristea
  • Status changed to Needs review 7 months ago
  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    Just a proof of concept. Should we go this way?

  • Pipeline finished with Canceled
    7 months ago
    Total: 504s
    #190520
  • Pipeline finished with Canceled
    7 months ago
    Total: 410s
    #190534
  • Pipeline finished with Success
    7 months ago
    Total: 522s
    #190544
  • πŸ‡¬πŸ‡§United Kingdom catch

    I tried to use autoconfigure on a different issue and ran into us not setting autoconfigure: true in various module services.yml files, so gave up.

    I think this is a good idea and can't think of any drawbacks, but am concerned that I could be missing something that this would break - i.e. could autoconfigure suddenly find classes that it currently doesn't and add tags to them etc?

    Also wondering whether we should require this to be set explicitly in all module services.yml files, issue a deprecation if it isn't, and then throw an exception in Drupal 12 - that way we could remove this code later and modules would have had to opt in or out by then.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    As discovered in πŸ“Œ Use autoconfigure more in core Active I'm not sure we can do this for autoconfigure at least.

    The example found there is that the mysql driver has a service which implements a Views interface. However, Views is not guaranteed to be available (in tests, and perhaps in a small number of real sites), so container rebuild crashes. I imagine that this scenario is more likely in contrib where a service has an optional dependency, and the service isn't used when the dependency isn't available.

  • πŸ‡©πŸ‡ͺGermany donquixote

    I did wonder why Symfony didn't just globally enable it

    I would imagine this is for BC reasons, same as here.
    There are probably plenty of existing packages that would break if symfony would enable autowire and autoconfigure by default.

  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Does seem to have some buy in. Maybe the tests could cover some of the concerns mentioned. Moving to NW for those.

Production build 0.71.5 2024