tyma...@gmail.com
unread,Apr 21, 2015, 3:53:16 PM4/21/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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?