Data Retrieval in a SignalR Hub/Service?
I am used to repo -> service -> controller MVC models, and I do not have much experience with in-memory retrieval beyond using LinQ.
Say I have a class which could have multiple queryable fields:
In a normal appcontextdb access scenario, I would just pull out the values using EFCore LinQ using something like
In my SignalR Hub, I am using an in-memory method and not SQL to store my data since I don't expect users to have long-lasting data (unlikely they will maintain a connection for >5minutes per session). Therefore I inject a
ConnectedClientsService
and don't have a DB table.
- Is using FirstOrDefaultAsync
with regular IQueryable is more standard practice in this case (for example, searching for strings matching region, etc)?
- Is it standard practice to use 2 concurrent dictionaries with a lock to enable O(1) access?4 Replies
For reference, this is my code:
I believe, for the concurrent dictionary, you don't need a lock object as it is thread safe.
Also, FirstOrDefault is fine, but make sure you register IConnectedClientsService as a singleton not scoped or transient.
Unknown User•3w ago
Message Not Public
Sign In & Join Server To View
The lock was to make modifying both dictionaries atomic, is it unnecessary in that case? 😳
I completely did not know this lmao I need to read up