Reputation: 12437
I want to map user's to connection id's when they connect to my hub class, what is a good strategy for doing this efficiently? I want to associate a user's profile with his connection id so when I check what users are in a particular signalr group I can each user's profile info easily
Upvotes: 2
Views: 512
Reputation: 33379
Technically if you're not worried about maintaining state you could solve this with a poor man's in memory ConcurrentDictionary<string, ConcurrentBag<string>>
, but I would assume you are trying to be a little more scalable/fault tolerant than that.
JabbR, which is the flagship testbed chat application for the SignalR framework, stores the connected client details in a table in its DB (which happens to be SQL). It has a mapping of the single ChatUser -> to many ChatClient instances (one-to-many). This way, when a logical user is logged in, it knows who that user is logically and can also make sure it can direct the proper messages to all the connected client instances that user might currently have open. You can find that specific implementation here if you're interested in learning more about it.
Upvotes: 4