public static void RegisterServices(this IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAspNetUser, AspNetUser>(); services.AddTransient <HttpClientAuthorizationDelegatingHandler>(); services.AddHttpClient <ICatalogService, CatalogService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICartService, CartService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <IOrderService, OrderService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICustomerService, CustomerService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); }
public static void RegisterServices(this IServiceCollection services, IConfiguration configuration) { services.AddSingleton <IValidationAttributeAdapterProvider, CpfValidationAttributeAdapterProvider>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAspNetUser, AspNetUser>(); #region httpServices services.AddTransient <HttpClientAuthorizationDelegatingHandler>(); services.AddHttpClient <IAuthenticateService, AuthenticateService>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICatalogService, CatalogService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() //.AddTransientHttpErrorPolicy( //p => p.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(600))); .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICustomerService, CustomerService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ISalesBffService, SalesBffService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.WaitAndRetry()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); #endregion #region Refit //services.AddHttpClient("Refit", options => //{ // options.BaseAddress = new Uri(configuration.GetSection("CatalogUrl").Value); //}) // .AddTypedClient(Refit.RestService.For<ICatalogServiceRefit>) // .AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>(); #endregion }