Circular dependency is when class “A” depends on class “B” to use their property for any requirement and the same class “B” depends on class “A” for some dependency in Project. This means to compile Project A you must first compile Project B, but you can’t do that as B requires A to be compiled. This is the problem that circular dependencies cause.
Example:-
class A { public $b; public function __construct(B $b) { $this->b = $b; } } class B { public $a; public function __construct(A $a) { $this->a = $a; } }Error:
Circular dependency: Magento\Store\Model\ResourceModel\Config\Collection\Scoped depends on Magento\Store\Model\ResourceModel\Config\Collection\Scoped and vice versa.

How to Resolve Circular Dependency?
- To fix the problem. Create a third class “C,” which contains the classes that both A and B depend on. So they no longer depend on each other.
- Combine class “A” and class “B” so you don’t need to depend on other classes if both classes code combine.
What is dependency injection in Magento 2?

Be the first to comment.