Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By qqboy on
in class, we use create function to injection service for constructon function.
So, may I ask why use create function as a middle layer, not directly use __construct?
for example this also works
public function __construct(ContainerInterface $container) {
return new static(
$this-> modulehandler = $container->get('module_handler'),
$this->config = $container->get('config.factory')
);
}
could some one help to make it clear ? thanks.
Comments
ok clear
ok clear
a layer for flexibility.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js