Example #1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddHttpClient();

            builder.Services.AddRefitClient <IGitHubAuthApi>(RefitExtensions.GetNewtonsoftJsonRefitSettings())
            .ConfigureHttpClient(client =>
            {
                client.BaseAddress = new Uri(GitHubConstants.GitHubBaseUrl);
                client.DefaultRequestHeaders.Authorization = getGitHubAuthenticationHeaderValue();
            })
            .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler {
                AutomaticDecompression = getDecompressionMethods()
            })
            .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

            builder.Services.AddRefitClient <IGitHubApiV3>(RefitExtensions.GetNewtonsoftJsonRefitSettings())
            .ConfigureHttpClient(client =>
            {
                client.BaseAddress = new Uri(GitHubConstants.GitHubRestApiUrl);
                client.DefaultRequestHeaders.Authorization = getGitHubAuthenticationHeaderValue();
            })
            .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler {
                AutomaticDecompression = getDecompressionMethods()
            })
            .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

            builder.Services.AddRefitClient <IGitHubGraphQLApi>(RefitExtensions.GetNewtonsoftJsonRefitSettings())
            .ConfigureHttpClient(client => client.BaseAddress = new Uri(GitHubConstants.GitHubGraphQLApi))
            .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler {
                AutomaticDecompression = getDecompressionMethods()
            })
            .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

            builder.Services.AddGitHubApiStatusService(getGitHubAuthenticationHeaderValue(), new ProductHeaderValue(nameof(GitTrends)))
            .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler {
                AutomaticDecompression = getDecompressionMethods()
            })
            .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

            builder.Services.AddSingleton <NuGetService>();
            builder.Services.AddSingleton <GitHubAuthService>();
            builder.Services.AddSingleton <GitHubApiV3Service>();
            builder.Services.AddSingleton <BlobStorageService>();
            builder.Services.AddSingleton <GitHubGraphQLApiService>();
            builder.Services.AddSingleton <CloudBlobClient>(CloudStorageAccount.Parse(_storageConnectionString).CreateCloudBlobClient());
Example #2
0
        static Task Main(string[] args)
        {
            var host = new HostBuilder()
                       .ConfigureAppConfiguration(configurationBuilder => configurationBuilder.AddCommandLine(args))
                       .ConfigureFunctionsWorkerDefaults()
                       .ConfigureServices(services =>
            {
                services.AddLogging();

                services.AddRefitClient <IGitHubAuthApi>(RefitExtensions.GetNewtonsoftJsonRefitSettings())
                .ConfigureHttpClient(client => client.BaseAddress = new Uri(GitHubConstants.GitHubBaseUrl))
                .ConfigurePrimaryHttpMessageHandler(config => new HttpClientHandler {
                    AutomaticDecompression = getDecompressionMethods()
                })
                .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

                services.AddRefitClient <IGitHubApiV3>(RefitExtensions.GetNewtonsoftJsonRefitSettings())
                .ConfigureHttpClient(client => client.BaseAddress = new Uri(GitHubConstants.GitHubRestApiUrl))
                .ConfigurePrimaryHttpMessageHandler(config => new HttpClientHandler {
                    AutomaticDecompression = getDecompressionMethods()
                })
                .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

                services.AddRefitClient <IGitHubGraphQLApi>(RefitExtensions.GetNewtonsoftJsonRefitSettings())
                .ConfigureHttpClient(client => client.BaseAddress = new Uri(GitHubConstants.GitHubGraphQLApi))
                .ConfigurePrimaryHttpMessageHandler(config => new HttpClientHandler {
                    AutomaticDecompression = getDecompressionMethods()
                })
                .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

                services.AddGitHubApiStatusService(new AuthenticationHeaderValue("bearer", _token), new ProductHeaderValue(nameof(GitTrends)))
                .ConfigurePrimaryHttpMessageHandler(config => new HttpClientHandler {
                    AutomaticDecompression = getDecompressionMethods()
                })
                .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider));

                services.AddSingleton <NuGetService>();
                services.AddSingleton <GitHubAuthService>();
                services.AddSingleton <GitHubApiV3Service>();
                services.AddSingleton <BlobStorageService>();
                services.AddSingleton <GitHubGraphQLApiService>();
                services.AddSingleton <BlobServiceClient>(new BlobServiceClient(_storageConnectionString));