Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.AddScoped() instead of .AddSingleton()? #2

Open
idylmz opened this issue Feb 10, 2024 · 0 comments
Open

.AddScoped() instead of .AddSingleton()? #2

idylmz opened this issue Feb 10, 2024 · 0 comments

Comments

@idylmz
Copy link

idylmz commented Feb 10, 2024

Hi,
I am trying to implement accu weather api to my application.

When I added the service as Singleton, my requests after the first one always gets exception about disposed Socket. I changed .AddSingleton to .AddScoped and there is no problem now.

The problem with AddSingleton:

Cannot access a disposed object.
Object name: 'System.Net.Http.SocketsHttpHandler'.
at System.Net.Http.SocketsHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Accuweather.Core.AccuweatherApiCore.SendGetRequest(String url)
at Accuweather.Locations.LocationsApi.GeoPositionSearch(Double lat, Double lon, Boolean details, Boolean topLevel)

I am not sure what should be done here but I think changing the documentation as AddScoped might be a good idea. Or am I missing something entirely else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant