Hello,
Did someone once faced a recursive error while using DI with service container in @laravelphp ? I've got a maximum call stack size reached. I have two services class that call each other
I have never had the error by doing exactly this, but it makes perfect sense that you are getting an error. Each is getting built over and over forever
Maybe binding them as singletons would fix it, but that can cause other issues if they aren't meant to be singletons
Thanks @sinnbeck . I thought Laravel bind as singleton by default. I'll try this.
@sinnbeck it didn't work even when using singleton.
I remove the `Aservice` automatic injection from `Bservice` class construct and create a function to resolve it .
It works fine.
class AService
{
public function __construct(
private readonly BService $bService
) {}
public function helloWorld(){
//
}
}
class BService
{
public function heyA(){
$this->aService()->helloWorld()
}
private aService(): Aservice{
return app(AService::class)
}
}