Chris Gomez

Development topics for the indie programmer

SignalR 2.0 brings us closer to OWIN

So I got tripped up at Central Penn.NET’s Code Camp with SignalR 2.0.  I realized there are a lot of blog posts that need to happen to explain some of the changes.

One of the great things about NuGet and the building of a .NET ecosystem around NuGet packages is that installing components you want to make your application go has never been easier.  It’s never been easier to stay up to date.  It’s never been easier to adopt new versions.

But there is such a thing as breaking changes…

In my talk yesterday about using SignalR in the real world, I got tripped up when doing the Stock Ticker that updates as stock prices change.  I know now that a breaking change in SignalR 2.0 obsoleted the common MVC era extension method for setup that many modules use.

In SignalR, you would go into your Application_Start method in Global.asax and add:

RouteTable.Routes.MapHubs();

Many components add an extension method to allow you to add routes with simple syntax, but it becomes custom syntax.  That does violate the spirit of OWIN a bit, and I think the SignalR team is definitely very supportive of OWIN.

So when you create an MVC project and use SignalR 2.0, you now following the OWIN standard and create a Startup class that has any startup logic you need.  In this case, it’s mapping our hubs:

This also means we say goodbye to the Microsoft.AspNet.SignalR.Owin NuGet package since this implementation doesn’t need the setup being provided by that package anymore.  More info on that in the SignalR faq.

So for now, here is a link to download the completed Stock Ticker sample.  I’m going to investigate now whether a different version of SignalR is automagically downloaded to you when you create your first SignalR Hub class via tooling or whether you go with NuGet.

I know that you can install specific versions of packages using NuGet, but I think most people don’t do this when they hit File > New Project.  It might be something I do from now on in presentations just to make sure something hasn’t changed, even in the last few days!

StockTicker Sample Download

blog comments powered by Disqus