Symfony how autowire a class specifique?

How can we have AutoWire active on calls in the 2nd child of the controller.

Here are different examples to explain my problem.

First exemple :

@Route("/user")

class UserControler extends AbstractController {

@Route("/", name="user_index", methods={"GET"})

public function index(UserRepository $userRepository) : Response {

if(!$userRepository instanceof UserRepository){
    throw new Exception('is not instance of UserRepository');}
}

  return new JsonResponse(['succes' => "test"]);
}

it’s ok, i don’t have problem here, the autowire has instantiate UserRepository


In this example, the Test1 class will be instantiated in the user controller, it takes a UserRepository in the contructor the auto wire will provide it

class Test1  {

    public function __construct (UserRepository $userRepository)  {

        if(!$userRepository instanceof UserRepository) {
            throw new Exception('is not instance of UserRepository');
        }
    }
} 
-
class UserControler extends AbstractController {

@Route("/", name="user_index", methods={"GET"})

public function index(Test1 $test1 ) : Response {
 


  return new JsonResponse(['succes' => "test"]);
}

None error trow, i have a instance of UserRepository, i can used it.


Now i want UserControler instanciate class Test1 and call method try().

The method try() instantiate the classe Test2 who need UserRepository in construtor.

class Test1  {

    public function try()  {
         new Test2();
         
    }
} 

class Test2  {

    public function __construct (UserRepository $userRepository)  {

        if(!$userRepository instanceof UserRepository) {
            throw new Exception('is not instance of UserRepository');
        }
    }
} 
-
class UserControler extends AbstractController {

@Route("/", name="user_index", methods={"GET"})

public function index(Test1 $test1 ) : Response {
 
  return new JsonResponse(['succes' => "test"]);
}

Autowire not working here, is possible ?