Last active
December 11, 2015 03:39
-
-
Save btompkins/4539509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Nancy.Hosting.Self; | |
using Topshelf; | |
namespace Nancy.Demo.Hosting.TopShelf | |
{ | |
public class NancySelfHost | |
{ | |
private NancyHost _nancyHost; | |
public void Start() | |
{ | |
_nancyHost = new NancyHost(new Uri("http://localhost:8888/nancy/")); | |
_nancyHost.Start(); | |
Console.WriteLine("Nancy now listening - http://localhost:8888/nancy/. Press ctrl-c to stop"); | |
} | |
public void Stop() | |
{ | |
_nancyHost.Stop(); | |
Console.WriteLine("Stopped. Good bye!"); | |
} | |
} | |
public class Program | |
{ | |
public static void Main() | |
{ | |
HostFactory.Run(x => //1 | |
{ | |
x.Service<NancySelfHost>(s => //2 | |
{ | |
s.ConstructUsing(name => new NancySelfHost()); //3 | |
s.WhenStarted(tc => tc.Start()); //4 | |
s.WhenStopped(tc => tc.Stop()); //5 | |
}); | |
x.UseLog4Net(); | |
x.RunAsLocalSystem(); //6 | |
x.SetDescription("Sample Topshelf Host"); //7 | |
x.SetDisplayName("Stuff"); //8 | |
x.SetServiceName("stuff"); //9 | |
}); //10 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment