public void Register <T>(Func <IContainer, T> constructor) where T : class { Func <TinyIoCContainer, T> theActualFunc = c => { var objFactory = new TinyIoCAdapter(c); return(constructor(objFactory)); }; this.container.Register((c, o) => theActualFunc(c)); }
protected override void ConfigureRequestContainer(TinyIoCContainer tinyIoCContainer, NancyContext context) { tinyIoCContainer.Register(this.GetAccessToken(context), "access_token"); tinyIoCContainer.Register <ITemplateService, TemplateService>(); tinyIoCContainer.Register <IRenderingService, RenderingService>(); var sitemapDomainName = ConfigurationManager.AppSettings["SitemapDomainName"]; tinyIoCContainer.Register <ISitemapService>((c, o) => new SitemapService(c.Resolve <IContentRepository>(), c.Resolve <IPathInstanceBuilder>(), sitemapDomainName)); tinyIoCContainer.Register <IContentRepository, ContentRepository>(); tinyIoCContainer.Register <IContentFinder, ContentFinder>(); tinyIoCContainer.Register <IPathInstanceBuilder, PathInstanceBuilder>(); tinyIoCContainer.Register <IDynamicSourceProvider, DynamicSourceProvider>(); tinyIoCContainer.Register <IPluginContextProvider, PluginContextProvider>(); var sourceTypes = KolaConfigurationRegistry.Plugins.SelectMany(plugin => plugin.SourceTypes).ToArray(); tinyIoCContainer.Register((c, o) => sourceTypes.Select(c.Resolve).Cast <IDynamicSource>()); var contentProviderTypes = KolaConfigurationRegistry.Plugins.SelectMany(plugin => plugin.ContextProviderTypes).ToArray(); tinyIoCContainer.Register((c, o) => contentProviderTypes.Select(c.Resolve).Cast <IContextProvider>()); var container = new TinyIoCAdapter(tinyIoCContainer); var componentSpecifications = KolaConfigurationRegistry.Plugins.SelectMany(plugin => plugin.ComponentTypeSpecifications); KolaConfigurationRegistry.RegisterRenderer(new MultiRenderer(new RendererFactory(componentSpecifications, container))); foreach (var plugin in KolaConfigurationRegistry.Plugins) { plugin.ConfigureContainer(container); } }