There is a tutorial of dependency injection in SignalR: http://www.asp.net/signalr/overview/signalr-20/extensibility/dependency-injection. Example is for NInject, but you can easily customize it. The thing you need to remember, is to config your DI container before initializing the SignalR (mapping the hubs).
Then you can register your hub context to be able to resolve it. Very important thing is, that you register hub context after hubs are mapped. Hub context can be saved into variable and stored as long as you like. Your Startup configure method would look like:
public void Configure(IAppBuilder app)
{
var resolver = new MyStructureMapResolver();
// configure depdendency resolver
GlobalHost.DependencyResolver = this.container.Resolve<IDependencyResolver>();
// map the hubs
app.MapSignalR();
// get your hub context
var hubContext = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
// register it in your structure map
ObjectFactory.Inject<IHubContext>(hubContext);
}
To have your hub context strongly typed, you can do something like that:
public interface INotificationHubContext {
void NotifyOthersAllOnLogin(string msg);
}
Then you make this:
// get your hub context
var hubContext = GlobalHost.ConnectionManager.GetHubContext<NotificationHub, INotificationHubContext>();
// register it in your structure map
ObjectFactory.Inject<IHubContext<INotificationHubContext>>(hubContext);
Hope this helps.