I have a class for making API calls. I would like to pass it as dependency and I want to know if it is better to use Singleton or Scoped :
services.AddScoped<IHttpCallService, HttpCallService>();
or
services.AddSingleton<IHttpCallService, HttpCallService>();
I know there are differences between Singleton and Scoped in terms of instance creation,
but I would like to know which one is more efficient and suitable for this case?
And also, if I use Singleton, would it mean that everything would work synchronously?
The recommomended pattern is to have your HttpCallService depend on an HttpClient instance, and then register it as a Typed Client with
services.AddHttpClient<HttpCallService>();
This will register HttpCallService as a transient service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With