Previously I talked about how to set up the server side of SignalR for facilitating real-time communication. One of the parts that I don’t particularly care for in that default implementation is that the hub methods (the messages that are sent to connected clients) are identified by strings. Sure, you could create some string constants to identify them, but that still leaves you without IntelliSense / knowing what parameters are expected when sending those messages.

via GIPHY

Strongly-Typed Hubs

Luckily, SignalR lets you define an interface that describes those message signatures, and then you can use it to have full IntelliSense to know what parameters are expected. This is especially useful when you’re injecting an IHubContext in to a different service.

Using this method makes things a lot cleaner. You don’t have to use magic strings or make a constants file, and you don’t have to hold the parameter list in your brain while you’re working.

via GIPHY