In our .NET API, we were creating the HttpClient
instances in each controller action. As the application should have a single instance of HttpClient
for each HTTP endpoint it consumes.
We have got a couple of options.
- Create a base controller class with
public readonly static HttpClient httpClient = new HttpClient()
and inherit all the controllers from this. - Each controller should have it's own
private readonly static HttpClient httpClient = new HttpClient()
declaration.
I am not sure if this will impact the performance (when thousands of users hit the application). Can anyone guide me to follow the right approach, please?