Search code examples
signalrsignalr-hub

SignalR - adding hubs at runtime


I have a working SignalR application, my global.asax.cs does all the usual MapHubs() etc, and I'm using a custom IAssemblyLocator which also loads in-memory assemblies as well as referenced assemblies. The two hubs I have are created at runtime in in-memory assemblies, and this works fine - hubs can push messages to clients etc.

At some point after the application has started, I want to add another hub at run time which will sit in it's own in-memory assembly, and make it appear in the signalr/hubs/ file.

How do I do this?

Calling MapHubs again results in an error because I already have the route defined. Removing the route (which I've only managed to do using RouteTable.Routes.Remove(RouteTable.Routes[0]) so far, and obviously isn't ideal) doesn't seem to work.

Is there a nice way to do this?


Solution

  • Use the alternate syntax instead of using the static signalr/hubs file since it will never update:

    http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-javascript-client#genproxy