SignalR Hub resolve

87 views
Skip to first unread message

tyma...@gmail.com

unread,
Apr 21, 2015, 3:53:16 PM4/21/15
to aut...@googlegroups.com
Hi,

I'm moving my SignalR app to use OWIN hosting and I have a problem I don't know how to solve. I have something like this in the OWIN configuration (simplified):


var builder = new ContainerBuilder();
//...

builder.RegisterHubs(typeof(MessageHub).Assembly)
.ExternallyOwned()
.PropertiesAutowired();

//..

var container = builder.Build();
var hubConfig = new HubConfiguration();
hubConfig.Resolver = new AutofacDependencyResolver(container);

app.MapSignalR("/signalr", hubConfig);


From the client-side, I can connect to the MessageHub and send/receive messages to/from it.

However, in one of my WebApi controllers I have:

public MessageController : ApiController {
public MessageHub Hub { get; set; } // DI

//...

public HttpResponseMessage Post() {
// Do something
Hub.Clients.All.send('done'); // This throws an exception
}
}

My ApiController-s are also properly registered within the same Autofac container (with PropertiesAutoWired) and Hub indeed gets resolved to a MessageHub instance (it's not null). However, its Context is null and trying to send out a message to all the clients like above results in an "Object reference not set to an instance of an object" exception. How do I get a proper MessageHub instance in a controller without using GlobalHost?
Message has been deleted

Travis Illig

unread,
Apr 22, 2015, 12:31:30 PM4/22/15
to aut...@googlegroups.com, tyma...@gmail.com
Is this question already somewhere on StackOverflow?

For a minute I thought it was here, but this appears to be somewhat different.

Generally usage questions get answered faster on StackOverflow; if you post there, please link back to the question here so we don't end up with duplication/cross-posting.

Igor Timarac

unread,
Apr 23, 2015, 5:44:13 PM4/23/15
to Travis Illig, aut...@googlegroups.com
Yes, sorry about that. Just after posting a question I realized that it's preferred to use Stackoverflow for that, so I posted question there.

I apologize once again.


Reply all
Reply to author
Forward
0 new messages