Signalr: getting hubcontext with unity di -


i started using unity inject stuff 1 of hubs. works, but, when resolve hubcontext somewhere outside hub seems i'm getting wrong one. because when try send messages it, connected clients don't them.

dependencyresolver:

public class signalrunitydependencyresolver : defaultdependencyresolver, idependencyresolver     {         private iunitycontainer _container;         public signalrunitydependencyresolver(iunitycontainer container)         {             _container = container;         }         public override object getservice(type servicetype)         {             if (_container.isregistered(servicetype)) return _container.resolve(servicetype);             else return base.getservice(servicetype);         }         public override ienumerable<object> getservices(type servicetype)         {             if (_container.isregistered(servicetype)) return _container.resolveall(servicetype);             else return base.getservices(servicetype);         }     } 

what register in container:

container.registertype<messagehub>(new injectionconstructor(new efauthrepository())); 

my hub:

public class messagehub : hub {     iauthrepository _repository;     public messagehub(iauthrepository repository)     {         _repository = repository;     } 

how resolve outside hub:

 var context = globalhost.connectionmanager.gethubcontext<messagehub>(); 

is there else needs registred?

you should use instance of resolver iconnectionmananger container explained here. althought ninject can idea. (look @ at bottom). connectionmanager can hubcontext used via globalhost.

resolver.resolve<iconnectionmanager>().gethubcontext<messagehub>() 

we made simple example ilustrate (ninject , unity examples using signalr) , can check out here. if eager setup, here. ;)

let me know if helps.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -