echo_

@is_coding


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



image

2

131

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

1

133

  • No matching results...
  • Searching...

/ 1000

Poll Options

echo_

@is_coding

Thanks @sinnbeck . I thought Laravel bind as singleton by default. I'll try this.

1

145

echo_

@is_coding

@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)
}
}

153