Beispiel #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);
        }
Beispiel #2
0
        private static async Task registerRunningNode(JasperRuntime runtime)
        {
            // TODO -- get a helper for this, it's ugly
            var settings = runtime.Get <BusSettings>();
            var nodes    = runtime.Get <INodeDiscovery>();

            try
            {
                var local = new ServiceNode(settings);
                local.HttpEndpoints = runtime.HttpAddresses?.Split(';').Select(x => x.ToUri().ToMachineUri()).Distinct()
                                      .ToArray();

                runtime.Node = local;

                await nodes.Register(local);
            }
            catch (Exception e)
            {
                runtime.Get <CompositeMessageLogger>()
                .LogException(e, message: "Failure when trying to register the node with " + nodes);
            }
        }
Beispiel #3
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);
        }
            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.Get <MessagingSettings>().ThrowOnValidationErrors)
                    {
                        recorder.AssertAllSuccessful();
                    }
                });

                _timer.Stop();

                return(_runtime.Container);
            }