- Issue created by @chesn0k
- πΊπ¦Ukraine chesn0k Ukraine, Odessa
chesn0k β changed the visibility of the branch 3409787-add-support-for to hidden.
- πΊπ¦Ukraine chesn0k Ukraine, Odessa
chesn0k β changed the visibility of the branch 3409787-add-support-for to active.
- Merge request !5879Added automatically wiring dependencies if ContainerInjectionInterface is not implemented. β (Open) created by chesn0k
- Status changed to Needs review
over 1 year ago 9:38am 10 January 2024 - Status changed to Needs work
over 1 year ago 2:15pm 10 January 2024 - πΊπΈUnited States smustgrave
Thanks for posting the MR.
Will need test coverage to ensure nothing breaks it in the future.
- Status changed to Needs review
over 1 year ago 4:30pm 11 January 2024 - πΊπΈUnited States smustgrave
Thanks! Change looks good to me but probably need to get reviewed by those more failure with the auto-wiring.
- Status changed to Needs work
about 1 year ago 10:52pm 28 January 2024 - π¬π§United Kingdom longwave UK
This looks like a nice feature but I think we should reuse (or refactor) AutowireTrait here if we can.
- πΊπ¦Ukraine chesn0k Ukraine, Odessa
Also, taking another look at the code, I noticed that there is no support for the union and intersection types. Should I put this in a separate issue?
- π¬π§United Kingdom longwave UK
What do you suggest instead of the trait? A service specifically for handling autowiring?
Yes, please open a new issue for union/intersection types. I can see a use for union types, not sure about intersection types.
- πΊπ¦Ukraine chesn0k Ukraine, Odessa
service specifically for handling autowiring
Good option, although I thought that this was the responsibility of the class resolver.
- π¬π§United Kingdom longwave UK
Plugins should also be autowireable, see π Allow plugin service wiring via constructor parameter attributes Needs work , hopefully we can unify some of the code there as well?
- πΊπ¦Ukraine chesn0k Ukraine, Odessa
Plugins should also be autowireable, see #3294266: Allow plugin service wiring via constructor parameter attributes, hopefully we can unify some of the code there as well?
Yes, this seems like a good reason to move autowire into a separate service.
This should also mean we can drop AutowireTrait from ControllerBase?
Yes.
- Status changed to Needs review
about 1 year ago 5:38pm 23 February 2024 - πΊπ¦Ukraine chesn0k Ukraine, Odessa
And so the current implementation of autowiring allows create a plugin instance in this way:
$instance = \Drupal::service(DependencyAutowire::class)->autowireClass( new \ReflectionClass($plugin_class), [ 'configuration' => $configuration, 'plugin_id' => $plugin_id, 'plugin_definition' => $plugin_definition, ], );
Plugin
__construct
:public function __construct( array $configuration, string $plugin_id, array $plugin_definition, protected readonly RouteMatchInterface $routeMatch, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); }
This is not bad, but I think the
__construct
method signature is too strict, plugins that not required to extends the base plugin could use property promotion:public function __construct( protected array $configuration, protected string $pluginId, protected array $pluginDefinition, protected readonly RouteMatchInterface $routeMatch, ) {}
I think we should search for arguments using snake_case and camelCase styles this can be implemented inside the dependency autowiring service.
Also should I remove all uses of AutowireTrait in current branch and mark as deprecated?
- Status changed to Needs work
about 1 year ago 11:03am 13 March 2024 The Needs Review Queue Bot β tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide β to find step-by-step guides for working with issues.