Example #1
0
        public static IServiceCollection ConfigureHttpClient(this IServiceCollection services)
        {
            services.AddHttpClient <IHttpClient, StandardHttpClient>()
            .AddPolicyHandler(HttpPolicy.GetRetryPolicy())
            .AddPolicyHandler(HttpPolicy.GetCircuitBreakerPolicy());

            return(services);
        }
Example #2
0
        public static IHttpClientBuilder AddPolicies(
            this IHttpClientBuilder clientBuilder,
            IConfiguration configuration
            )
        {
            var policyOptions = configuration.Get <PolicyOptions>();

            return(clientBuilder.AddPolicyHandler(HttpPolicy.GetTimeout(policyOptions.Timeout))
                   .AddPolicyHandler(HttpPolicy.GetRetryPolicy(policyOptions.HttpRetry))
                   .AddPolicyHandler(HttpPolicy.GetCircuitBreakerPolicy(policyOptions.HttpCircuitBreaker)));
        }