Sponsorship is available! If you’d like to sponsor CodeOpinion.com and have your product or service advertised exclusively (no AdSense) on every post, contact me.Although there isn’t an “official” of Nancy v2 release yet, there’ is 2.0.0-clinteastwood that’s been in NuGet since Dec 12th, 2106 and as of this post has almost 200k downloads. The primary reason for upgrading Nancy to v2 is because of its support for NETStandard 1.6 which means you can move to .NET Core. In this demo, I’m going to be using ASP.NET Core with Owin and Nancy 2.0.0-clinteastwood to add back in the existing routing functionality that is a breaking change in v2.
Breaking ChangesThere’s an upgrade notes page on the Nancy Wiki, which lists some of the breaking changes. Although there aren’t many, and I suspect most of the work for the 2.0 release was for targeting NETStandard. The most glaring breaking change is with routing.
Routing syntax has changed toThis is really significant. In Nancy V1, you specified routes using the following: If you have a large web app with many routes and modules, although a trivial change, this could take some significant time.
Get("/", args => "Hello World");, these can be made
asyncby adding the
async/awaitkeywords. For more info see the PR where it all changed https://github.com/NancyFx/Nancy/pull/2441
NancyV1ModuleI decided to try to create a new module that would add back the existing routing behavior by calling the new underlying methods in the NancyModule. This would allow me to simply change all my existing modules to extend this new class rather than the new Module in Nancy v2.
UsageThis then adds back in all the existing routing. Just simply extend