SignalR per-request lifetime dependencies (patch)

41 views
Skip to first unread message

Philip Garrett

unread,
Mar 29, 2015, 11:55:07 PM3/29/15
to aut...@googlegroups.com
Hi. I saw that the Autofac SignalR integration docs say "due to SignalR internals, there is no support in SignalR for per-request lifetime dependencies." I had an idea to make this work using Castle DynamicProxy, and it turns out to work pretty well.

I've added a new method, RegisterHubWithLifetimeScope<T> that registers a dynamically generated subclass of T in place of T. When a Hub instance is requested, it creates a new implicit lifetime scope. The lifetime scope gets disposed when the owning Hub is disposed. The generated class is only loaded once so performance is good.

It all works because SignalR creates a new instance of the Hub for every operation.

Code is at github:
https://github.com/kingpong/Autofac.SignalR/compare/support-hub-lifetimescope

Any fatal flaws I'm overlooking? I'm interested to get this or something like it merged in at some point.

Thanks,
Philip

Travis Illig

unread,
Mar 30, 2015, 12:28:59 PM3/30/15
to aut...@googlegroups.com, phil...@gmail.com
I'm no SignalR expert, but I'm curious how this changes with the DNX runtime coming up in ASP.NET vNext. Given they've unified a lot in the way of Web API and MVC, have they changed anything for SignalR?

-T
Reply all
Reply to author
Forward
0 new messages