I have a signalr client that I want to be global.
I think creating the signalr client in the Init() of the endpointconfig would be best.
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization{ public static HubConnection hubConnection; public static IHubProxy hubProxy; public void Init() { Configure.With() .DefiningEventsAs(t => t.Namespace != null && t.Namespace.Contains(".Events.")) .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.Contains(".Messages.")) .StructureMapBuilder(new Container(new DependencyRegistry())); Configure.Serialization.Json(); hubConnection = new HubConnection("http://localhost:58120"); hubProxy = hubConnection.CreateHubProxy("AmsHub"); hubProxy.On<string>("receiveServerPush", x => System.Diagnostics.Debug.WriteLine(x)); hubConnection.Start().Wait(); } public class DependencyRegistry : Registry { public DependencyRegistry() { Scan(x => { x.AssembliesFromApplicationBaseDirectory(); x.ExcludeNamespace("StructureMap"); x.WithDefaultConventions(); }); } }}
What I'm confused about, is how am I supposed to reference the hubConnection and hubProxy in a message handler? I seems like I'm jerry rigging NServicebus.
public class TestHandler : IHandleMessages<AMS.Infrastructure.Events.IEvent>{ public void Handle(AMS.Infrastructure.Events.IEvent message) { EndpointConfig.hubProxy.Invoke("ServerFunction", "yodle"); }}
PS: the reason I need the connection and proxy to be global is because spawning up a new hubConnection is expensive according to the signalr people. They highly discourage creating and destroying hubconnections over and over again. They found that making the hubconnection global/static(?) ok though.