Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR 1.0 beta connection factory

Tags:

signalr

Now that the new version of SignalR has done away with the IConnectionFactory interface, what is the recommended pattern to use to set the connection id of a client?

like image 900
Heather Avatar asked Feb 18 '23 20:02

Heather


1 Answers

There is no longer any recommended pattern for setting the connection id of a SignalR client in 1.0.

The best practice is to maintain state on your SignalR server that maps your application's users to a connection id. The obvious place to add connection ids to this map is in OnConnected. You can use OnDisconnected to remove connection ids.

Another option, which could also be done in OnConnected, is to add the client's connection id to a group with the name you would have created for the client in IConnectionIdFactory.CreateConnectionId before. Naturally, that group would only contain the one client, so you can send all the messages you would have sent to the custom connection id to the group instead.

Note: If you go with the mapping option you might also attempt adding connection ids to the map in OnReconnected if you are concerned about AppDomain restarts and you are storing this state in some sort of static variable instead of something more persistent. Obviously you would need shared state for this if you are scaling out SignalR.

like image 149
halter73 Avatar answered Feb 28 '23 09:02

halter73