I am developing an API, in this API I have a service with a method and this method has to call three methods in different repositories. Each of this methods have a Https request, the call has a respond and I want to get the information from this respond.
Now, we are waiting for each of this calls and the performance is awful.
How can I do these three call to the same time? I know using parallel but I don't know how.
Service:
public async Task<object> GetTenantSettings(string source, string tenantId)
{
var tenantSettings = await _repository1.GetTenant(tenantId);
var accountCount = await _repository2.GetAccount(tenantId);
var userCount = await _repository3.GetUsers(source, int.Parse(tenantId));
var TenantSettingsModel = MapTenant(accountCount, userCount, tenantSettings); // To map, out of scope of the problem
return TenantSettingsModel;
}
The interface of the repository, I show one but all have the same idea.
Task<int> GetAccount(string tenantId);
Now we are calling one method and after the others, how can I call it to the same time and get the information?