D8 Dependency Injection (DI)
Blocks, Controllers, Forms
protected $db;
protected $requestStack;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database'),
$container->get('request_stack')
);
}
/**
* {@inheritdoc}
*/
public function __construct(Connection $db, RequestStack $requestStack) {
$this->db = $db;
$this->requestStack = $requestStack;
}Roll your own service
Last updated
Was this helpful?