Skip to content

Upgrading Nancy to Version 2

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Upgrading NancyAlthough 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 Changes

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

Routing syntax has changed to Get("/", args => "Hello World");, these can be made async by adding the async/await keywords. 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.

NancyV1Module

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.

Usage

This then adds back in all the existing routing.  Just simply extend NancyV1Module instead of NancyModule.

Upgrading Nancy

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.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Leave a Reply

Your email address will not be published. Required fields are marked *