Пример #1
0
        public FubuRuntime Bootstrap()
        {
            SetupNamingStrategyForHttpHeaders();

            _fubuFacility = new FubuMvcPackageFacility();

            IServiceFactory factory = null;
            BehaviorGraph   graph   = null;

            // TODO -- I think Bottles probably needs to enforce a "tell me the paths"
            // step maybe
            PackageRegistry.GetApplicationDirectory = FubuMvcPackageFacility.GetApplicationPath;
            BottleFiles.ContentFolder  = FubuMvcPackageFacility.FubuContentFolder;
            BottleFiles.PackagesFolder = FileSystem.Combine("bin", FubuMvcPackageFacility.FubuPackagesFolder);

            IList <RouteBase> routes = null;

            PackageRegistry.LoadPackages(x => {
                x.Facility(_fubuFacility);
                _packagingDirectives.Each(d => d(x));

                x.Bootstrap(log => {
                    // container facility has to be spun up here
                    var containerFacility = _facility.Value;

                    // Need to do this to make the provenance for bottles come out right
                    _registry.Value.Config.Seal();

                    applyFubuExtensionsFromPackages();

                    graph = buildBehaviorGraph();

                    bakeBehaviorGraphIntoContainer(graph, containerFacility);

                    // factory HAS to be spun up here.
                    factory = containerFacility.BuildFactory();

                    routes = buildRoutes(factory, graph);
                    routes.Each(r => RouteTable.Routes.Add(r));
                    containerFacility.Register(typeof(FubuRouteTable), ObjectDef.ForValue(new FubuRouteTable {
                        Routes = routes
                    }));

                    return(factory.GetAll <IActivator>());
                });
            });

            FubuMvcPackageFacility.Restarted = DateTime.Now;

            PackageRegistry.AssertNoFailures(
                () => { throw new FubuException(0, FubuApplicationDescriber.WriteDescription()); });


            var runtime = new FubuRuntime(factory, _facility.Value, routes);

            _facility.Value.Register(typeof(FubuRuntime), ObjectDef.ForValue(runtime));

            return(runtime);
        }
Пример #2
0
        public FubuRuntime Bootstrap()
        {
            SetupNamingStrategyForHttpHeaders();

            _fubuFacility = new FubuMvcPackageFacility();

            // TODO -- I think Bottles probably needs to enforce a "tell me the paths"
            // step maybe
            PackageRegistry.GetApplicationDirectory = FubuMvcPackageFacility.GetApplicationPath;
            BottleFiles.ContentFolder  = FubuMvcPackageFacility.FubuContentFolder;
            BottleFiles.PackagesFolder = FileSystem.Combine("bin", FubuMvcPackageFacility.FubuPackagesFolder);


            FubuRuntime runtime = null;

            Task <IList <RouteBase> > routeTask = null;

            PackageRegistry.LoadPackages(x => {
                x.Facility(_fubuFacility);
                _packagingDirectives.Each(d => d(x));

                x.Bootstrap("FubuMVC Bootstrapping", log => {
                    // container facility has to be spun up here
                    var containerFacility = _facility.Value;

                    var perfTimer = PackageRegistry.Timer;

                    perfTimer.Record("Applying IFubuRegistryExtension's", applyFubuExtensionsFromPackages);

                    var graph = perfTimer.Record("Building the BehaviorGraph", () => buildBehaviorGraph());

                    perfTimer.Record("Registering services into the IoC Container",
                                     () => bakeBehaviorGraphIntoContainer(graph, containerFacility));

                    // factory HAS to be spun up here.
                    var factory = perfTimer.Record("Build the IServiceFactory",
                                                   () => containerFacility.BuildFactory(graph));

                    routeTask = perfTimer.RecordTask("Building Routes", () => {
                        var routes = buildRoutes(factory, graph);
                        routes.Each(r => RouteTable.Routes.Add(r));

                        return(routes);
                    });


                    _facility.Value.Register(typeof(FubuRouteTable), ObjectDef.ForValue(new FubuRouteTable(routeTask)));

                    runtime = new FubuRuntime(factory, _facility.Value, routeTask.Result);

                    _facility.Value.Register(typeof(FubuRuntime), ObjectDef.ForValue(runtime));

                    return(factory.GetAll <IActivator>());
                });
            });


            FubuMvcPackageFacility.Restarted = DateTime.Now;

            PackageRegistry.AssertNoFailures(
                () => { throw new FubuException(0, FubuApplicationDescriber.WriteDescription()); });



            return(runtime);
        }