Example #1
0
        public static void EnsureConfigurations([NotNull] Type applicationType, [NotNull] IVostokHostingEnvironmentBuilder builder)
        {
            void SetupSource(IConfigurationProvider provider, IConfigurationSource source, string[] scope, Type type)
            {
                if (scope.Any())
                {
                    source = source.ScopeTo(scope);
                }

                provider.SetupSourceFor(source, type);
            }

            builder.SetupConfiguration(
                b => b.CustomizeConfigurationContext(
                    context =>
            {
                foreach (var requirement in RequirementDetector.GetRequiredConfigurations(applicationType))
                {
                    SetupSource(context.ConfigurationProvider, context.ConfigurationSource, requirement.Scope, requirement.Type);
                }

                foreach (var requirement in RequirementDetector.GetRequiredSecretConfigurations(applicationType))
                {
                    SetupSource(context.SecretConfigurationProvider, context.SecretConfigurationSource, requirement.Scope, requirement.Type);
                }
            }));
        }
        public void Should_support_composite_applications()
        {
            var application = new MultiApplication();

            RequirementDetector.RequiresPort(application).Should().BeTrue();

            RequirementDetector.GetRequiredConfigurations(application)
            .Should()
            .ContainSingle()
            .Which.Type.Should()
            .Be(typeof(string));

            var extensions = RequirementDetector.GetRequiredHostExtensions(application).ToArray();

            extensions.Should().HaveCount(4);

            extensions[0].Type.Should().Be(typeof(IGenericInterface <string>));
            extensions[1].Type.Should().Be(typeof(IGenericInterface <string>));
            extensions[2].Type.Should().Be(typeof(Guid));
            extensions[3].Type.Should().Be(typeof(int));
        }
Example #3
0
        public static void AddVostokEnvironment(this IServiceCollection services, IVostokHostingEnvironment environment, IVostokApplication application)
        {
            services
            .AddSingleton(environment)
            .AddSingleton(environment.ApplicationIdentity)
            .AddSingleton(environment.ApplicationLimits)
            .AddTransient(_ => environment.ApplicationReplicationInfo)
            .AddSingleton(environment.Metrics)
            .AddSingleton(environment.Log)
            .AddSingleton(environment.Tracer)
            .AddSingleton(environment.HerculesSink)
            .AddSingleton(environment.ConfigurationSource)
            .AddSingleton(environment.ConfigurationProvider)
            .AddSingleton(environment.ClusterConfigClient)
            .AddSingleton(environment.ServiceBeacon)
            .AddSingleton(environment.ServiceLocator)
            .AddSingleton(environment.ContextGlobals)
            .AddSingleton(environment.ContextProperties)
            .AddSingleton(environment.ContextConfiguration)
            .AddSingleton(environment.Datacenters)
            .AddSingleton(environment.HostExtensions);

            foreach (var(type, obj) in environment.HostExtensions.GetAll())
            {
                services.AddSingleton(type, obj);
            }

            if (environment.HostExtensions.TryGet <IVostokApplicationDiagnostics>(out var diagnostics))
            {
                services
                .AddSingleton(diagnostics.Info)
                .AddSingleton(diagnostics.HealthTracker);
            }

            AddSettingsProviders(services, RequirementDetector.GetRequiredConfigurations(application).Select(r => r.Type), environment.ConfigurationProvider);
            AddSettingsProviders(services, RequirementDetector.GetRequiredSecretConfigurations(application).Select(r => r.Type), environment.SecretConfigurationProvider);

            services.AddScoped(_ => FlowingContext.Globals.Get <IRequestInfo>());
        }