Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot pass a DependencyResolver to MapSignalR in a HubConfiguration

Tags:

signalr

I have a MVC 4 app where I'm using SignalR and a dependency injection framework. Thus, I needed to implement a custom DependencyResolver. In order to wire it up, I'm using

        var resolver = new CustomSignalRDependencyResolver(...);
        GlobalHost.DependencyResolver = resolver;
        app.MapSignalR();

and everything works as expected. However, if I use a HubConfiguration object like this:

        var resolver = new CustomSignalRDependencyResolver(...);
        app.MapSignalR(new HubConfiguration(
            {
                Resolver = resolver
            });

everything seems to work (the objects are correctly wired-up, there are no errors or warning whatsoever) but the remote methods are not invoked anymore. Can someone explain the difference between the first and the second approach?

like image 666
Dejan Avatar asked Nov 28 '25 18:11

Dejan


1 Answers

I think Lars Höppner (the user who left the first comment on this post) is right.

You can definitely use a custom dependency resolver without changing GlobalHost.DependencyResolver (the SignalR test suite does this quite often), but you have to be sure GlobalHost doesn't show up anywhere else in your code.

This means that absolutely no references to:

  • GlobalHost.Configuration
  • GlobalHost.ConnectionManager
  • GlobalHost.TraceManager
  • GlobalHost.HubPipeline
  • and of course GlobalHost.DependencyResolver

The SO post Lars linked to (SignalR: Sending data using GlobalHost.ConnectionManager not working) shows you how to get the ConnectionManager from your custom dependency resolver; you can do the same thing for all the other properties on GlobalHost.

like image 181
halter73 Avatar answered Dec 02 '25 03:12

halter73



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!