Chris Gomez

Development topics for the indie programmer

Philly.NET Code Camp 2013.2 - SignalR

Thanks to everyone who attended my talk about using SignalR “in the real world.”  Besides being an introduction to SignalR for everyone who’s curious about this technology, we talked about some more advanced scenarios I have experience with, including using the IHubContext interface to broadcast from outside a SignalR Hub and the exciting “cross platform” scenario that is enabled by the several SignalR clients out there.

I wanted to start getting all the code we looked at up on github.  I will continue to update this post until all the samples we saw are ready for you to try.

https://github.com/spaceshot/chatter – This is the repository holding the chat web app and windows store app.  They should work together.

I did develop these projects in Visual Studio 2013, which has built in Git support and it is a lot easier to clone the projects directly from GitHub and begin working.  If you have a need for Visual Studio 2012 support, please let me know.

Up next, I need to get the StockTicker sample (modifying an existing service) up and finally the “game board” sample where you could move game tokens around a sample grid.

Coming soon are my tutorial writeups for those who didn’t make the code camp talk!

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