Many thanks for @Bruce (SqlWork.com) 's code sample and it remind me a lot.
In my humble opinion, it seems to be not a good idea to call Controller by the services, that's because when we designed a Controller, it should play the role like an entrance & exit so that an http request can reach and got response.
private readonly HttpClient _httpClient;
private readonly IServiceA _servA;
private readonly IServiceB _servB;
public Test(HttpClient httpClient, IServiceA servA, IServiceB servB)
{
_httpClient = httpClient;
_servA = servA;
_servB = servB;
}
[HttpPost]
[Route("/api/test/Process")]
[Authorized]
public async Task ProcessAsync([FromServices] Test tp, [FromBody] JObject joData)
{
//doing service A to get or save some data e.g. var a = _servA.testAsycn(tp);
//doing service B to get or save some data e.g. var b = _servB.DoSth(joData);
//.....
// combine all the data and saving data response into a response and return.
}
So your code await tp.TestAsync("myToken...XXXX");
should be abstracted to a service and you need to pass the data Test tp
into the service.
Then your private async Task Test(){}
should call the service instead of the controller.
Calling service method, you may need to use dependency inject.