public static void RegisterServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton <IValidationAttributeAdapterProvider, CpfValidationAttributeAdapterProvider>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <IAspNetUser, AspNetUser>();


            services.AddTransient <HttpClientAuthorizationDelegatingHandler>();
            services.AddHttpClient <IAuthService, AuthService>()
            .AddPolicyHandler(PollyExtensions.CustomRetryAsync())
            .AddTransientHttpErrorPolicy(p =>
                                         p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)));

            services.AddHttpClient <IPurshaseBFFService, PurshaseBFFService>()
            .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>()
            .AddPolicyHandler(PollyExtensions.CustomRetryAsync())
            .AddTransientHttpErrorPolicy(p =>
                                         p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)));
            ;
            services.AddHttpClient <ICatalogService, CatalogService>()
            .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>()
            //.AddTransientHttpErrorPolicy(
            //    p => p.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(500)))
            .AddPolicyHandler(PollyExtensions.CustomRetryAsync())
            .AddTransientHttpErrorPolicy(p =>
                                         p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)));

            //services.AddHttpClient("Refit",
            //    opt => { opt.BaseAddress = new Uri(configuration.GetSection("CatalogUrl").Value); })
            //    .AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()
            //    .AddTypedClient(Refit.RestService.For<ICatalogServiceRefit>);
        }
Esempio n. 2
0
        public static void AddDependencyInjectionConfiguration(this IServiceCollection services)
        {
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <IAspNetUser, AspNetUser>();
            services.AddTransient <HttpClientAuthorizationDelegatingHandler>();


            services.AddHttpClient <ICartService, CartService>()
            .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>()
            .AddPolicyHandler(PollyExtensions.CustomRetryAsync())
            .AddTransientHttpErrorPolicy(p =>
                                         p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)));
            ;
            services.AddHttpClient <ICatalogService, CatalogService>()
            .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>()
            //.AddTransientHttpErrorPolicy(
            //    p => p.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(500)))
            .AddPolicyHandler(PollyExtensions.CustomRetryAsync())
            .AddTransientHttpErrorPolicy(p =>
                                         p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)));
        }