You can load your code into separate AppDomain
and use shadow copying for hot reload. Suppose you have nancy application like this:
static void Main(string[] args) {
using (var host = new NancyHost(new Uri("http://localhost:34455"))) {
host.Start();
Console.WriteLine("started");
Console.ReadKey();
}
}
public class SampleModule : Nancy.NancyModule {
public SampleModule() {
Get["/"] = _ => "Hello World!";
}
}
And you want to be able to update it without restarting hosting process. You can do it like this (warning - non-production ready code, just sample). Create another application like this:
static void Main() {
while (true) {
var setup = new AppDomainSetup();
setup.ApplicationBase = @"Path to directory with your nancy app";
setup.ShadowCopyFiles = "true";
var domain = AppDomain.CreateDomain("Nancy", new Evidence(), setup);
domain.ExecuteAssembly(@"Path to your nancy app exe");
AppDomain.Unload(domain);
}
}
Then start your second (host) application. It will create new app domain and start your nancy application in it. Now you can update your nancy application while host application is running (right in that folder - because of shadow copying, files are not locked). To apply updates - press any key in host application. This will tear down app domain with your old version and create new app domain with new version, without restarting process.
Using this technique you can for example watch directory with your application via FileSystemWatcher
and replace app domain on changes to application files. You can also minimize downtime by first loading new appdomain to the point before starting your nancy host, then tearing down old app domain and then start nancy host in new app domain.