Created
January 13, 2011 12:09
-
-
Save jfromaniello/777768 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
public class NancyEngineProvider : INancyBootStrapper, INancyModuleCatalog | |
{ | |
private readonly ContainerBuilder containerBuilder; | |
private IContainer container; | |
private bool isInitialized; | |
public NancyEngineProvider() | |
{ | |
containerBuilder = new ContainerBuilder(); | |
} | |
public INancyEngine GetEngine() | |
{ | |
if (!isInitialized) Initialize(); | |
return container.Resolve<INancyEngine>(); | |
} | |
private void Initialize() | |
{ | |
containerBuilder.RegisterType<ModuleCatalog>() | |
.As<INancyModuleCatalog>(); | |
//in castle you don't need an implementation for this. simply "AsFactory". | |
containerBuilder.RegisterType<RouteResolver>() | |
.As<IRouteResolver>() | |
.SingleInstance(); | |
containerBuilder.RegisterType<DefaultTemplateEngineSelector>() | |
.As<ITemplateEngineSelector>().SingleInstance(); | |
containerBuilder.RegisterType<NancyEngine>() | |
.As<INancyEngine>() | |
.SingleInstance(); | |
//register all modules of the assembly | |
container = containerBuilder.Build(); | |
isInitialized = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment