So we've got a container, service providers and, with inversion of control, we can do fancy stuff like:
public function __construct(CarServiceInterface $carService)
{
}
And things get resolved nicely because somewhere else...
$container->bind(CarServiceInterface::class, function ()
{
return new CarService();
});
Let's say car service depends on human service. Then...
$container->bind(CarServiceInterface::class, function (Container $container)
{
return new CarService($container->make(HumanServiceInterface::class);
});
Hey, that works. Cool.
But then suddenly humans NEED cars, and the human service is built like this:
$container->bind(HumanServiceInterface::class, function (Container $container)
{
return new HumanService($container->make(CarServiceInterface::class);
});
Voila, cross dependency.
How to solve this?
Is this consequence of a flaw in the design?
Thanks!