Implement a Dependency Injection Container (DIC) to manage object creation and lifecycle. DICs help in decoupling components, improving testability, and managing complex dependency graphs in large applications.
use Psr\Container\ContainerInterface;
class UserService
{
private $db;
public function __construct(ContainerInterface $container)
{
$this->db = $container->get('database');
}
}