Ben Cameron Ben Cameron - 1 year ago 127
C# Question

Web API and SignalR - the correct way?

I am looking to start a project in which I need to make push updates from Web API.

I found this post which gives an example of how to do this.

Can I incorporate both SignalR and a RESTful API?

This demo uses a class called


You extend your web api controllers from this.

This post is quite old now (2013). Is this still the correct way to do things or have there been developments in Web API to allow for push updates?

Answer Source

I don´t think there´s a new integration between web api controllers and hubs. That code is totally fine.

The key part is:

Lazy<IHubContext> hub = new Lazy<IHubContext>(
    () => GlobalHost.ConnectionManager.GetHubContext<THub>()

You can implement that code the way you want. But the sample code is a nice way to use it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download