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.
There’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 to
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
This 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.
I 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.
This then adds back in all the existing routing. Just simply extend
NancyV1Module instead of
I’ve created a console application with the source available on GitHub.
Have you ran into any significant issues when upgrading Nancy to v2? Please let me know on Twitter or in the comments.