Closed conekeo closed 4 years ago
WPF as in "Windows Presentation Foundation", the desktop framework? I don't see how that's related to Nancy?
Yes, Windows Presentation Foundation. I just want to create an WPF app an integrate Nancy in it. But I don't know where to start. I just want to handle a simple
Get("/", args => "Hello World");
Check out Nancy's self hosting documentation, I've been using it in a console application for years: https://github.com/NancyFx/Nancy/wiki/Self-Hosting-Nancy
I saw the console application, but I'm looking for simple WPF implementation.
It’s the same code. You would just set it up and store it to a static variable in your application initialization code since it doesn’t exist the same way a console app does.
@phillip-haydon Could you elaborate more on how to implement it? Here what I got so far
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
using (var host = new NancyHost(new Uri("http://localhost:80")))
{
host.Start();
Console.WriteLine("NancyFX Stand alone test application.");
}
HelloModule hello = new HelloModule();
}
}
HelloModule.cs
public class HelloModule : NancyModule
{
public HelloModule()
{
Get("/", parameters => "Hello World");
}
}
@conekeo You never initialize the Nancy modules by yourself, that is the work of the Bootstrapper (see Wiki) where it scans the current assembly looking for the modules and registering them (along with their dependencies).
A NancyHost
takes a bootstrapper as argument, so you should implement one first:
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
// your customization goes here
}
}
@Zaid-Ajaj Thanks! All right it's working!
Here my WPF working sample:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
NancyHost host = new NancyHost(new Bootstrapper(), new Uri("http://localhost:80"));
host.Start();
Console.WriteLine("NancyFX Stand alone test application.");
}
}
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
// your customization goes here
}
}
public class HelloModule : NancyModule
{
public HelloModule()
{
Get("/", parameters => "Hello World");
}
}
Hi,
Could someone redirect me to a good WPF with Nancy v2 tutorial? Or how do I implement that?
Thanks!