Can I incorporate both SignalR and a RESTful API?

Take a look at the video from this blog post. It explains exactly how you can use WebAPI with SignalR.

Essentially, Web API + SignalR integration consists in this class:

public abstract class ApiControllerWithHub<THub> : ApiController
    where THub : IHub
{
    Lazy<IHubContext> hub = new Lazy<IHubContext>(
        () => GlobalHost.ConnectionManager.GetHubContext<THub>()
    );

    protected IHubContext Hub
    {
        get { return hub.Value; }
    }
}

That’s all. 🙂

Leave a Comment