Hi @aethdae ,
services dependent on IHttpContextAccessor are being registered as scoped or transient. Is there a reason for this or is it safe to call register services that depend on IHtppContextAccessor as singletons?
For this issue, I think it depends on the service lifetimes:
Transient lifetime services are created each time they're requested from the service container. In apps that process requests, transient services are disposed at the end of the request.
Scoped services are created once per client request (connection). In apps that process requests, scoped services are disposed at the end of the request.
Singleton lifetime services are created the first time they are requested (or when ConfigureServices is run if you specify an instance there) and then every subsequent request will use the same instance. In apps that process requests, singleton services are disposed when the ServiceProvider is disposed on application shutdown. Because memory is not released until the app is shut down, consider memory use with a singleton service.
From the above description, we can know that Transient and Scoped services are created based on the request and will be disposed at the end of the request. But the Singleton service is not, it will disposed when the Service Provider is released when the application closes. So if you register all your services as singletons, you might cause out of memory issues.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion