I just updated some SignalR links and things have changed a bit to allow typed Hub<T> hubs. In existing examples and documentation, such as:
Server-Broadcast-with-Signalr
we have a static class containing references to clients through the following mechanisms:
public class StockTicker() { private readonly static Lazy<StockTicker> _instance = new Lazy<StockTicker>( () => new StockTicker(GlobalHost.ConnectionManager.GetHubContext<StockTickerHub>().Clients)); IHubConnectionContext Clients {get;set;} private StockTicker(IHubConnectionContext clients) { Clients = clients; } }
So, the static link is checked, and if null is:
GlobalHost.ConnectionManager.GetHubContext<StockTickerHub>().Clients
to instantiate and provide clients through the constructor.
So that was how it worked, and indeed, how it has a url in it. But now with Hub<T> in the constructor a small change is required:
private StockTicker(IHubConnectionContext<dynamic> clients) { Clients = clients; }
Now my question is how can I extend this further so that my version of StockTicker can have a strongly typed property for clients like x.
IHubConnectionContext<StockTickerHub> Clients {get;set;} private StockTicker(IHubConnectionContext<dynamic> clients) { Clients = clients;
By supporting strongly typed links, I could call strongly typed methods, etc.
rism
source share