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

qqboy’s picture