1 year ago
#75810
Santi
Doubts about concurrency in injected services in ASP.NET Core
I have a service injected into the ASP.NET dotnet framework service container. I inject this service as a Singleton, and its function is to maintain several data structures (Dictionay, List, Queue) in memory.
The service is perfectly accessible from the controllers, and my doubts are due to the lack of knowledge of the internal workings of ASP.NET.
My questions are:
- Should I worry about creating the Singleton (thread safe) or does the container take care of it?
- Are accesses to service methods enqueued in a single thread?, or can they be called concurrently? I ask to know if I have to use Concurrent Collections instead of the Generic ones.
- Would it be convenient to make the methods asynchronous?
I accept any suggestion, and examples.
Thanks in advance.
c#
asp.net-core
dependency-injection
async-await
concurrency
0 Answers
Your Answer