Trouble with Dependency Injection in Laravel 9 causing Circular Reference scenarios
I just started working with I'm learning this framework and I'm sure I'm missing something obvious here, but I'm using Laravel 9 and I'm working with a `Circular reference detected` behavior when trying to inject dependencies into my controllers... I have two services, `ServiceA` and `ServiceB`, where `ServiceA` depends on `ServiceB`, and vice versa, like this: ```php class ServiceA { protected $serviceB; public function __construct(ServiceB $serviceB) { $this->serviceB = $serviceB; } } class ServiceB { protected $serviceA; public function __construct(ServiceA $serviceA) { $this->serviceA = $serviceA; } } ``` When I try to resolve `ServiceA` in my controller, I get the behavior message: ``` Illuminate\Container\EntryNotFoundException: Circular reference detected. ``` I've tried to refactor the services to eliminate the circular dependency by using interfaces and separating the concerns, but it didn't help. I also thought about using method injection instead of constructor injection, but I need both services available for other methods in the classes. Can someone guide to with best practices for handling this kind of situation in Laravel? Whatβs the recommended approach to prevent circular dependencies while still maintaining clean code? For reference, this is a production mobile app. What would be the recommended way to handle this? Any feedback is welcome!