1

I'm trying to use the Unit Of Work pattern with RavenDb and SignalR. However, I can't find a clear SignalR Hub event to use as the hook to call SaveChanges on my RavenDb document session.

If it was MVC I'd use Application_EndRequest in Global.asax or OnActionExecuted in my Controller, but what equivalent is there for a SignalR Hub?

Robin Weston
  • 873
  • 2
  • 10
  • 24

1 Answers1

1

You could register a custom Hub pipeline module that overrides the HubPipelineModule.OnAfterIncoming method.

OnAfterIncoming will be called upon the completion of each Hub method.

halter73
  • 15,059
  • 3
  • 49
  • 60
  • Thanks. I did spy this method, but it wasn't clear if it does what I'm after. I think it's because there is an [OnAfterOutgoing](http://msdn.microsoft.com/en-us/library/microsoft.aspnet.signalr.hubs.hubpipelinemodule.onafteroutgoing(v=vs.111).aspx) method as well. Can you shed any light on that? I'll put in some trace statements in my code to see the order of evaluation – Robin Weston May 23 '14 at 08:27
  • So this is the order of events (assuming your Hub method sends a message to a client): OnBeforeIncoming, OnBeforeOutgoing, OnAfterOutgoing, OnAfterIncoming. Looks good to me, consider your answer accepted! – Robin Weston May 23 '14 at 18:25
  • The OnBeforeOutgoing and OnAfterOutgoing methods are similar to OnBeforeIncoming and OnAfterIncoming but for invocations in the opposite direction. The Incoming methods are for *client-to-server* calls, whereas the Outgoing methods for *server-to-client* calls. – halter73 May 23 '14 at 18:36
  • One other key difference between OnAfterIncoming and OnAfterOutgoing is that OnAfterIncoming executes after the server-side Hub method completes while OnAfterOutgoing may execute before clients receive the Hub method invocation. OnAfterOutgoing does indicate indicate a hub invocation message has successfully been published to a message bus however. – halter73 May 23 '14 at 18:45