Skip to content
Snippets Groups Projects

Added automatically wiring dependencies if ContainerInjectionInterface is not implemented.

1 unresolved thread

Closes #3409787

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
27 29 if (is_subclass_of($definition, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) {
28 30 $instance = $definition::create($this->container);
29 31 }
32 elseif (method_exists($definition, '__construct')) {
33 $constructor = new \ReflectionMethod($definition, '__construct');
  • Given that this is largely a copy of AutowireTrait, can we just use AutowireTrait directly in this class (perhaps by refactoring it a bit if we need to), instead of copy-pasting?

    There are existing bugs like https://www.drupal.org/project/drupal/issues/3410222 so when we fix similar issues it would be good to do it in one place only.

  • Yes, I agree that this should be implemented in one place but the trait seems like a bad solution. What if we mark AutowireTrait as deprecated?

    Also using a trait will cause more problems if we need to implement a static cache (I did a small benchmark: using reflection is about half as slow).

    can we just use AutowireTrait directly in this class (perhaps by refactoring it a bit if we need to)

    I think it's not difficult, but over time I would prefer to remove the trait.

  • Is a static cache worth it? How often do we autowire the same object during a request? And tbh if we do is that not a problem in and of itself?

  • I didn't measure the number of same objects being autowire. Also I don't think this is a problem since the object being created can have state (likee plugins).

  • Alexander Yureskul changed this line in version 8 of the diff

    changed this line in version 8 of the diff

  • Please register or sign in to reply
  • added 2 commits

    • 48e343aa - Added service for auto-wire dependencies.
    • 3b547041 - Use DependencyAutowire service in AutowireTrait.

    Compare with previous version

  • Alexander Yureskul added 272 commits

    added 272 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading