コード例 #1
0
        protected override void InitializeServiceCollection()
        {
            var gitHubApiV3Client    = RefitExtensions.For <IGitHubApiV3>(CreateServerErrorHttpClient(GitHubConstants.GitHubRestApiUrl));
            var gitHubGraphQLCLient  = RefitExtensions.For <IGitHubGraphQLApi>(BaseApiService.CreateHttpClient(GitHubConstants.GitHubGraphQLApi));
            var azureFunctionsClient = RefitExtensions.For <IAzureFunctionsApi>(BaseApiService.CreateHttpClient(AzureConstants.AzureFunctionsApiUrl));

            ServiceCollection.Initialize(azureFunctionsClient, gitHubApiV3Client, gitHubGraphQLCLient);
        }
コード例 #2
0
        public async Task <IActionResult> Get(int id)
        {
            var quoteClient = RefitExtensions.InstanciateClient <IQuoteClient>(RefitConfig.GetHttpClient());

            var result = (await quoteClient.GetQuote(id)).Content;

            //var result = (await this.QuoteClient.GetQuote(id)).Content;
            return(this.Ok(result));
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: nefisekula/GitTrends
        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());
コード例 #4
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));
コード例 #5
0
 /// <summary>
 /// Executes upon middleware invocation
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public async Task Invoke(HttpContext context)
 {
     await RefitExtensions.WithExceptionDetailsAsync(() => _next(context), _logger, _options);
 }