Exemplo n.º 1
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            if (registry.Logging.UseConsoleLogging)
            {
                registry.Services.AddTransient <IMessageLogger, ConsoleMessageLogger>();
                registry.Services.AddTransient <ITransportLogger, ConsoleTransportLogger>();
            }


            var timer = new PerfTimer();

            timer.Start("Bootstrapping");

            timer.Record("Finding and Applying Extensions", () => { applyExtensions(registry); });

            timer.Record("Bootstrapping Settings", () => registry.Settings.Bootstrap());


            var handlerCompilation = registry.Bus.CompileHandlers(registry, timer);


            var services = registry.CombinedServices();

            var runtime         = new JasperRuntime(registry, services, timer);
            var featureBuilding = registry.BuildFeatures(runtime, timer);

            await handlerCompilation;
            await registry.Bus.Activate(runtime, registry.Generation, timer);

            await featureBuilding;

            await registry.Startup(runtime);

            // Run environment checks
            timer.Record("Environment Checks", () =>
            {
                var recorder = EnvironmentChecker.ExecuteAll(runtime);
                if (runtime.Get <BusSettings>().ThrowOnValidationErrors)
                {
                    recorder.AssertAllSuccessful();
                }
            });

            timer.MarkStart("Register Node");
            await registerRunningNode(runtime);

            timer.MarkFinished("Register Node");

            timer.Stop();

            return(runtime);
        }
Exemplo n.º 2
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            applyExtensions(registry);

            registry.Settings.Bootstrap();

            var features = registry.Features;

            var serviceRegistries = await Task.WhenAll(features.Select(x => x.Bootstrap(registry)))
                                    .ConfigureAwait(false);

            var collections = new List <IServiceCollection>();

            collections.AddRange(serviceRegistries);
            collections.Add(registry.ExtensionServices);
            collections.Add(registry.Services);


            var services = await ServiceCollectionExtensions.Combine(collections.ToArray());

            registry.Generation.ReadServices(services);


            var runtime = new JasperRuntime(registry, services);

            registry.Http.As <IWebHostBuilder>().UseSetting(WebHostDefaults.ApplicationKey, registry.ApplicationAssembly.FullName);

            runtime.HttpAddresses = registry.Http.As <IWebHostBuilder>().GetSetting(WebHostDefaults.ServerUrlsKey);

            await Task.WhenAll(features.Select(x => x.Activate(runtime, registry.Generation)))
            .ConfigureAwait(false);

            // Run environment checks
            var recorder = EnvironmentChecker.ExecuteAll(runtime);

            if (runtime.Get <BusSettings>().ThrowOnValidationErrors)
            {
                recorder.AssertAllSuccessful();
            }

            await registerRunningNode(runtime);

            return(runtime);
        }
Exemplo n.º 3
0
            public IServiceProvider ConfigureServices(IServiceCollection services)
            {
                var others = services
                             .Where(x => x.ServiceType == typeof(IStartup))
                             .Where(x => x.ImplementationInstance != this).ToArray();

                services.RemoveAll(s => others.Contains(s));

                var combined = _runtime.Registry.CombineServices(services);

                combined.AddSingleton(_runtime);

                // TODO -- need to pass in the perf timer here
                _runtime.Container = new Container(combined);

                _startups = others.Select(x => Build(_runtime.Container, x)).ToArray();

                var additional = new ServiceCollection();

                // I know this is goofy as all hell, but there is code
                // in MVC that tries to pick things out of the service collection
                // during bootstrapping
                additional.AddRange(services);


                foreach (var startup in _startups)
                {
                    startup.ConfigureServices(additional);
                }

                // See the rant-y comment above
                additional.RemoveAll(services.Contains);

                _runtime.Container.Configure(additional);

                if (!_runtime.Container.Model.HasRegistrationFor <IServer>())
                {
                    _runtime.Container.Configure(x => x.AddSingleton <IServer>(new NulloServer()));
                }

                if (_runtime.Registry.HttpRoutes.Enabled)
                {
                    _runtime
                    .Registry
                    .HttpRoutes
                    .FindRoutes(_runtime, _runtime.Registry, _timer)
                    .GetAwaiter()
                    .GetResult();
                }

                _handlerCompilation.GetAwaiter().GetResult();


                // Run environment checks
                _timer.Record("Environment Checks", () =>
                {
                    var recorder = EnvironmentChecker.ExecuteAll(_runtime);
                    if (_runtime.Registry.MessagingSettings.ThrowOnValidationErrors)
                    {
                        recorder.AssertAllSuccessful();
                    }
                });

                _timer.Stop();

                return(_runtime.Container);
            }
Exemplo n.º 4
0
        private static async Task <JasperRuntime> bootstrap(JasperRegistry registry)
        {
            var timer = new PerfTimer();

            timer.Start("Bootstrapping");

            timer.Record("Finding and Applying Extensions", () =>
            {
                applyExtensions(registry);
            });

            var buildingServices = Task.Factory.StartNew(() =>
            {
                return(timer.Record("Combining Services and Building Settings", registry.CompileConfigurationAndServicesForIdiomaticBootstrapping));
            });



            var handlerCompilation = registry.Messaging.CompileHandlers(registry, timer);


            var runtime = new JasperRuntime(registry, timer);

            var services = await buildingServices;

            services.AddSingleton(runtime);


            var container = await Lamar.Container.BuildAsync(services, timer);

            container.DisposalLock = DisposalLock.Ignore;
            runtime.Container      = container;


            var routeDiscovery = registry.HttpRoutes.Enabled
                ? registry.HttpRoutes.FindRoutes(runtime, registry, timer)
                : Task.CompletedTask;

            runtime.buildAspNetCoreServer(services);

            await routeDiscovery;

            await Task.WhenAll(runtime.startAspNetCoreServer(), handlerCompilation, runtime.startHostedServices());


            // Run environment checks
            timer.Record("Environment Checks", () =>
            {
                var recorder = EnvironmentChecker.ExecuteAll(runtime);
                if (runtime.Settings.ThrowOnValidationErrors)
                {
                    recorder.AssertAllSuccessful();
                }
            });

            _lifetime = TypeExtensions.As <ApplicationLifetime>(container.GetInstance <IApplicationLifetime>());
            _lifetime.NotifyStarted();

            timer.Stop();

            return(runtime);
        }