Created
January 13, 2011 15:39
-
-
Save jfromaniello/778061 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//bootstrapper: | |
public class DemoBootStrapper : INancyBootStrapper | |
{ | |
private readonly Lazy<IWindsorContainer> containerInitializator | |
= new Lazy<IWindsorContainer>(Initialize); | |
private static IWindsorContainer Initialize() | |
{ | |
var container = new WindsorContainer(); | |
container.AddFacility<TypedFactoryFacility>(); | |
container.Kernel.Resolver | |
.AddSubResolver(new CollectionResolver(container.Kernel, true)); | |
//run all installers for this assembly | |
container.Install(FromAssembly.This()); | |
return container; | |
} | |
public INancyEngine GetEngine() | |
{ | |
var nancyEngine = containerInitializator.Value.Resolve<INancyEngine>(); | |
return nancyEngine; | |
} | |
} | |
//Nancy basic stuff installer | |
public class NancyInstaller : IWindsorInstaller | |
{ | |
public void Install(IWindsorContainer container, IConfigurationStore store) | |
{ | |
container.Register | |
( | |
Component.For<INancyModuleCatalog>().AsFactory(), | |
Component.For<IRouteResolver>().ImplementedBy<RouteResolver>(), | |
Component.For<ITemplateEngineSelector>().ImplementedBy<DefaultTemplateEngineSelector>(), | |
Component.For<INancyEngine>().ImplementedBy<NancyEngine>() | |
); | |
} | |
} | |
//NancyModule installer by convention - register all from this assembly | |
public class NancyModuleInstaller : IWindsorInstaller | |
{ | |
public void Install(IWindsorContainer container, IConfigurationStore store) | |
{ | |
container.Register(AllTypes.FromThisAssembly() | |
.BasedOn<NancyModule>() | |
.Configure(c => c.LifeStyle.Transient)); | |
} | |
} | |
//Other installer: | |
public class OtherDependencyInstaller : IWindsorInstaller | |
{ | |
public void Install(IWindsorContainer container, IConfigurationStore store) | |
{ | |
container.Register(Component.For<IDependency>() | |
.ImplementedBy<DependencyClass>()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment