I'm on an MVC3 project and I am using snap structuremap for my dependecy injection. Everything was in-place, except when I started using SignalR where I can't seem to implement my DI like I have on my controllers. I've been googling about implementing structuremap DI on SignalR for days now, but haven't found a strong sample on how to do this. Seems like everyone that are using SignalR are using Ninject.
My goal is to have conditional statements (which requires me to inject services) inside my Hub before calling my client methods, but I had no success on this.
I didn't want this thing to delay my development so I researched for alternative ways, then I found out that I can actually call my client methods from my controllers using the following codes:
IConnectionManager connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>();
dynamic clients = connectionManager.GetClients<MyHub>();
clients.myClientScript();
This works for me, but I'm not sure if this is a good approach - especially that I am using dependency injection.
So my question is: Is it ok to keep calling this inside my controller? Do you have a better approach?
Thanks