// TOOD -- clean this up a little bit public static BehaviorGraph Build(FubuRegistry registry) { var graph = new BehaviorGraph { ApplicationAssembly = registry.ApplicationAssembly }; var config = registry.Config; PackageRegistry.Timer.Record("Applying Settings", () => applySettings(config, graph)); var viewDiscovery = graph.Settings.Get <ViewEngineSettings>().BuildViewBag(graph); var layoutAttachmentTasks = viewDiscovery.ContinueWith( t => graph.Settings.Get <ViewEngineSettings>().Facilities.Select(x => x.LayoutAttachment).ToArray()); graph.Settings.Replace(viewDiscovery); AccessorRulesCompiler.Compile(graph); var htmlConventionCollation = HtmlConventionCollator.BuildHtmlConventions(graph); addBuiltInDiagnostics(graph); PackageRegistry.Timer.Record("Local Application BehaviorGraph", () => config.BuildLocal(graph)); viewDiscovery.RecordContinuation("View Attachment", t => { var attacher = new ViewAttachmentWorker(t.Result, graph.Settings.Get <ViewAttachmentPolicy>()); attacher.Configure(graph); }).Wait(); PackageRegistry.Timer.Record("Explicit Configuration", () => config.Global.Explicits.RunActions(graph)); PackageRegistry.Timer.Record("Global Policies", () => config.Global.Policies.RunActions(graph)); PackageRegistry.Timer.Record("Inserting Conneg and Authorization Nodes", () => insertConnegAndAuthorizationNodes(graph)); PackageRegistry.Timer.Record("Applying Global Reorderings", () => config.ApplyGlobalReorderings(graph)); PackageRegistry.Timer.Record("Applying Tracing", () => applyTracing(graph)); // Wait until all the other threads are done. var registration = htmlConventionCollation.ContinueWith(t => config.RegisterServices(graph)); Task.WaitAll(registration, layoutAttachmentTasks); Task.WaitAll(layoutAttachmentTasks.Result); new AutoImportModelNamespacesConvention().Configure(graph); return(graph); }
public FubuRuntime(FubuRegistry registry) { _registry = registry; _appFunc = new Lazy <AppFunc>(() => FubuOwinHost.ToAppFunc(this)); RouteTable.Routes.Clear(); _diagnostics = new ActivationDiagnostics(); _perfTimer = _diagnostics.Timer; _perfTimer.Start("FubuRuntime Bootstrapping"); var packageAssemblies = AssemblyFinder.FindModuleAssemblies(_diagnostics); var applicationPath = registry.RootPath ?? DefaultApplicationPath(); _files = new FubuApplicationFiles(applicationPath); _perfTimer.Record("Applying IFubuRegistryExtension's", () => applyFubuExtensionsFromPackages(_diagnostics, packageAssemblies, registry)); _container = registry.ToContainer(); var graph = _perfTimer.Record("Building the BehaviorGraph", () => BehaviorGraphBuilder.Build(registry, _perfTimer, packageAssemblies, _diagnostics, _files)); _perfTimer.Record("Registering services into the IoC Container", () => registry.Config.RegisterServices(Mode, _container, graph)); _factory = new StructureMapServiceFactory(_container); var routeTask = _perfTimer.RecordTask("Building Routes", () => { var routes = buildRoutes(_factory, graph); routes.Each(r => RouteTable.Routes.Add(r)); return(routes); }); var library = HtmlConventionCollator.BuildHtmlConventions(graph); _container.Configure(_ => { _.Policies.OnMissingFamily <SettingPolicy>(); _.For <IFubuApplicationFiles>().Use(_files); _.For <IServiceLocator>().Use <StructureMapServiceLocator>(); _.For <FubuRuntime>().Use(this); _.For <IServiceFactory>().Use(_factory); _.For <HtmlConventionLibrary>().Use(library); }); Activate(); _routes = routeTask.Result(); if (registry.Host != null) { startHosting(); } _perfTimer.Stop(); Restarted = DateTime.Now; _diagnostics.AssertNoFailures(); }