Exemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services
            .AddMvc()
            .AddRazorOptions(options => options.ParseOptions = new CSharpParseOptions(LanguageVersion.CSharp7));;

            if (UseGoogleCloudStorage)
            {
                // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
                // request processing.
                services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
                services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
                services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, GoogleStorageBenchmarkRepository>();
            }
            else
            {
                services.AddSingleton <IReleaseRepository, FakeReleaseRepository>();
                services.AddSingleton <ITzdbRepository, FakeTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, FakeBenchmarkRepository>();
            }
            services.AddSingleton <MarkdownLoader>();
            services.AddMemoryCache();
        }
Exemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            services.Configure <ForwardedHeadersOptions>(
                options => options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto);

            if (UseGoogleCloudStorage)
            {
                // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
                // request processing.
                services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
                services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
                services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, GoogleStorageBenchmarkRepository>();
            }
            else
            {
                services.AddSingleton <IReleaseRepository, FakeReleaseRepository>();
                services.AddSingleton <ITzdbRepository, FakeTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, FakeBenchmarkRepository>();
            }
            services.AddSingleton <MarkdownLoader>();
            services.AddMemoryCache();
        }
Exemplo n.º 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            services.AddSingleton(provider => GoogleCredentialProvider.FetchCredential(Configuration));
            services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
        }
Exemplo n.º 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
            // request processing.
            services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
            services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
            services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
            services.AddSingleton <MarkdownLoader>();
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
            // request processing.
            services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
            services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
            services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
            // TODO: We'll take a hit of loading all the Markdown the first time this is used.
            // It would be better to load eagerly at startup, assuming we don't just want to do everything
            // lazily...
            services.AddSingleton <MarkdownLoader>();
        }
Exemplo n.º 6
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            StackdriverOptions.ConfigureServices(services, CurrentEnvironment);
            NetworkOptions.ConfigureServices(services);

            // TODO: Add actual health checks, maybe.
            services.AddHealthChecks();

#if BLAZOR
            services.AddResponseCompression(options =>
            {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
                {
                    MediaTypeNames.Application.Octet,
                    WasmMediaTypeNames.Application.Wasm,
                });
            });
#endif

            if (UseGoogleCloudStorage)
            {
                // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
                // request processing.
                services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
                services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
                services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, GoogleStorageBenchmarkRepository>();
            }
            else
            {
                services.AddSingleton <IReleaseRepository, FakeReleaseRepository>();
                services.AddSingleton <ITzdbRepository, FakeTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, LocalBenchmarkRepository>();
            }
            services.AddSingleton <MarkdownLoader>();
            services.AddMemoryCache();
        }
Exemplo n.º 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.Configure <ForwardedHeadersOptions>(
                options => options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto);

#if BLAZOR
            services.AddResponseCompression(options =>
            {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
                {
                    MediaTypeNames.Application.Octet,
                    WasmMediaTypeNames.Application.Wasm,
                });
            });
#endif

            if (UseGoogleCloudStorage)
            {
                // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
                // request processing.
                services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
                services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
                services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, GoogleStorageBenchmarkRepository>();
            }
            else
            {
                services.AddSingleton <IReleaseRepository, FakeReleaseRepository>();
                services.AddSingleton <ITzdbRepository, FakeTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, FakeBenchmarkRepository>();
            }
            services.AddSingleton <MarkdownLoader>();
            services.AddMemoryCache();
        }
Exemplo n.º 8
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // TODO: Put this into appsettings.json.
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.KnownNetworks.Clear();
                // Google Cloud Platform load balancers
                options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("130.211.0.0"), 22));
                options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("35.191.0.0"), 16));
                // GKE service which proxies the request as well.
                options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("10.0.0.0"), 8));
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
                options.ForwardLimit     = 2;
            });

            services.AddHttpsRedirection(options =>
            {
                // TODO: Put this into appsettings.json?
                // (When hosted on GKE, we don't locally host HTTPS, so we need to specify the port.
                // But in development, we need to stick with 5001.)
                if (!CurrentEnvironment.IsDevelopment() && CurrentEnvironment.EnvironmentName != "smoketests")
                {
                    options.HttpsPort = 443;
                }
                options.RedirectStatusCode = 301;
            });

            // TODO: Add actual health checks, maybe.
            services.AddHealthChecks();

#if BLAZOR
            services.AddResponseCompression(options =>
            {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
                {
                    MediaTypeNames.Application.Octet,
                    WasmMediaTypeNames.Application.Wasm,
                });
            });
#endif

            if (StackdriverOptions.UseStackdriverErrorReporting)
            {
                var platform = Platform.Instance();
                services.AddGoogleExceptionLogging(options =>
                {
                    options.ServiceName = StackdriverOptions.ServiceName ?? platform.GkeDetails?.ContainerName ?? "aspnetcore";
                    options.Version     = StackdriverOptions.ServiceVersion ?? CurrentEnvironment.EnvironmentName;
                });
            }

            if (UseGoogleCloudStorage)
            {
                // Eagerly fetch the GoogleCredential so that we're not using Task.Result in
                // request processing.
                services.AddSingleton(GoogleCredentialProvider.FetchCredential(Configuration));
                services.AddSingleton <IReleaseRepository, GoogleStorageReleaseRepository>();
                services.AddSingleton <ITzdbRepository, GoogleStorageTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, GoogleStorageBenchmarkRepository>();
            }
            else
            {
                services.AddSingleton <IReleaseRepository, FakeReleaseRepository>();
                services.AddSingleton <ITzdbRepository, FakeTzdbRepository>();
                services.AddSingleton <IBenchmarkRepository, LocalBenchmarkRepository>();
            }
            services.AddSingleton <MarkdownLoader>();
            services.AddMemoryCache();
        }