di-containers

Circular dependency - Injecting objects that are directly depended on each other

这一生的挚爱 提交于 2019-12-30 08:14:41
问题 I have used Dice PHP DI container for quite a while and it seems the best in terms of simplicity of injecting dependencies. From Dice Documentation: class A { public $b; public function __construct(B $b) { $this->b = $b; } } class B { } $dice = new \Dice\Dice; $a = $dice->create('A'); var_dump($a->b); //B object However, when you have to use objects that are directly dependent on each other, the finall result is server error, because of the infinite loop . Example: class A { public $b; public

Circular dependency - Injecting objects that are directly depended on each other

人盡茶涼 提交于 2019-12-01 03:38:45
I have used Dice PHP DI container for quite a while and it seems the best in terms of simplicity of injecting dependencies. From Dice Documentation : class A { public $b; public function __construct(B $b) { $this->b = $b; } } class B { } $dice = new \Dice\Dice; $a = $dice->create('A'); var_dump($a->b); //B object However, when you have to use objects that are directly dependent on each other, the finall result is server error, because of the infinite loop . Example: class A { public $b; public function __construct(B $b) { $this->b = $b; } } class B { public $a; public function __construct(A $a