简体   繁体   中英

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?

http://bradwilson.typepad.com/blog/2012/07/webstack-of-love.html

This demo uses a class called ApiControllerWithHub<THub> 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?

I don´t think there´sa 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM