I appeal to the knowledge of the community to resolve a doubt about the use of services, about whether it is feasible to use the functionalities of one service within another.
I have two two defined services whose nomeclature is as follows:
GestorSolicitudController
GestorTurnosController
If in the GestorTurnoController , I try to call a function declared in GestorTurnosController as follows:
$servicio = $this->container->get('gestor_solicitudes');
$solicitud = $servicio->obtenerSolicitudActual($dni);
I get the error Call to a member function get () on null Provisionally, I solved it using dependency injection, declaring an attribute in the following way:
class GestorTurnoController extends Controller
{
protected $entityManager;
//usamos injeccion de dependencias porque no puedo usar un servicio en otro
//to-do ver como resolverlo
protected $solicitudes;
public function __construct($entityManager)
{
$this->entityManager = $entityManager;
$this->solicitudes = new GestorSolicitudController($entityManager);
}
In this way, it works correctly. But I have the doubt if it is that you can not use a service within another, if it is feasible you can tell me how and if not, what is resolved with dependency injection. Thanks!