One of the great thing about Nancy is that you can host it in pretty much every­where, and that includes inside a con­sole app! The doc­u­men­ta­tions seems to be miss­ing the self-hosting option how­ever, but it’s easy and only takes a minute.

First, cre­ate a con­sole app and get the Nancy.Hosting.Self pack­age from NuGet:

image

Then you write your mod­ule code and then sim­ply cre­ate an instance of Nan­cy­Host with the base URL you want to use and call the Start() method to start host­ing! It just couldn’t be eas­ier :-D

Here’s a quick example:

Enjoy!

Share

One Response to “Nancy self hosting”

  1. […] So what are your options for doing this?  If you already have an exist­ing .NET appli­ca­tion run­ning on your device, with state, etc. spin­ning up IIS and a web site isn’t a great option.. You will have to tackle issues of shar­ing data, instal­la­tion of the web site every time you setup a new device, the over­head of run­ning IIS, IIS secu­rity, just to name a few.  What if there was a sim­ple way of gen­er­at­ing an HTTP end­point? – Enter Nancy Self Hosting. […]

Leave a Reply