Skip to content

Instantly share code, notes, and snippets.

@tarasn
Created August 26, 2015 07:27
Show Gist options
  • Save tarasn/915189476b94d54251c4 to your computer and use it in GitHub Desktop.
Save tarasn/915189476b94d54251c4 to your computer and use it in GitHub Desktop.
Using Castle.Windsor with nancyfx via WindsorNancyBootstrapper (https://github.com/NancyFx/Nancy/issues/1792)
using System;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Nancy;
using Nancy.Bootstrappers.Windsor;
using Nancy.Hosting.Self;
namespace ConsoleApplication1
{
public interface IFoo
{
string Text { get; }
}
public class Foo : IFoo
{
public Foo()
{
Text = "Some component text";
}
public string Text { get; private set; }
}
public class Bootstrapper : WindsorNancyBootstrapper
{
protected override void ConfigureApplicationContainer(IWindsorContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register(Component.For<IFoo>().ImplementedBy<Foo>().LifestyleSingleton());
}
}
public class ResourceModule : NancyModule
{
public ResourceModule(IFoo foo)
{
Get["/text"] = parameters => { return "Some non meanigfull text ..." + foo.Text; };
}
}
internal class Program
{
private static void Main(string[] args)
{
using (var host = new NancyHost(new Uri("http://localhost:1234")))
{
host.Start();
Console.ReadLine();
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment