public static void RegisterServices(this IServiceCollection services) { services.AddSingleton <IValidationAttributeAdapterProvider, CpfValidationAttributeAdapterProvider>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAspNetUser, AspNetUser>(); #region HttpServices services.AddTransient <HttpClientAuthorizationDelegatingHandler>(); services.AddHttpClient <IAutenticacaoService, AutenticacaoService>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICatalogoService, CatalogoService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <IComprasBffService, ComprasBffService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); #endregion }
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>); }
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) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAspNetUser, AspNetUser>(); services.AddTransient <HttpClientAuthorizationDelegatingHandler>(); services.AddHttpClient <ICatalogoService, CatalogoService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICarrinhoService, CarrinhoService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <IPedidoService, PedidoService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <IClienteService, ClienteService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); }
public static void RegisterServices(this IServiceCollection services, IConfiguration configuration) { services.AddSingleton <IValidationAttributeAdapterProvider, CpfValidationAttributeAdapterProvider>(); services.AddTransient <HttpClientAuthorizationDelegatingHandler>(); // pq trasiente, pq chama uma estancia de cada vez services.AddHttpClient <IAutenticacaoService, AutenticacaoService>(); services.AddHttpClient <ICatalogoService, CatalogoService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() //.AddTransientHttpErrorPolicy( //p => p.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(600))); .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //porque singleton, porque tenho que estudar services.AddScoped <IUser, AspNetUser>(); //adicionar via scoped, fica limitado ao request #region Refit //services.AddHttpClient("Refit", // options => // { // options.BaseAddress = new Uri(configuration.GetSection("CatalogoUrl").Value); // }) // .AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>() // .AddTypedClient(Refit.RestService.For<ICatalogoServiceRefit>); #endregion }
public static void RegisterServices(this IServiceCollection services, IConfiguration configuration) { services.AddSingleton <IValidationAttributeAdapterProvider, CpfValidationAttributeAdapterProvider>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAspNetUser, AspNetUser>(); services.AddTransient <HttpClientAutorizationDelegatingHandler>(); services.AddHttpClient <IAutenticacaoService, AutenticacaoService>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy(p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICatalogoService, CatalogoService>() .AddHttpMessageHandler <HttpClientAutorizationDelegatingHandler>() // .AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(retryCount: 3, sleepDurationProvider: _=> TimeSpan.FromMilliseconds(600))); .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy(p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <IComprasBffService, ComprasBffService>() .AddHttpMessageHandler <HttpClientAutorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy(p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); #region Refit config //services.AddHttpClient("Refit", options => { // options.BaseAddress = new Uri(configuration.GetSection("CatalogoUrl").Value); //}).AddHttpMessageHandler<HttpClientAutorizationDelegatingHandler>() //.AddTypedClient(Refit.RestService.For<ICatalogoService>); #endregion }
public void ConfigureServices(IServiceCollection services) { services.AddHttpClient <ProdutoApiClient>(); services.AddHttpClient <WaitAndRetryApiClient>().AddPolicyHandler(PollyExtensions.PollyWaitAndRetry()); services.AddHttpClient <CircuitBreakerApiClient>().AddPolicyHandler(PollyExtensions.PollyCircuitBreaker()); services.AddControllersWithViews(); }
private static IServiceCollection ResolveHttpServices(this IServiceCollection services) { services.AddHttpClient <IAuthenticationFacade, AuthenticationFacade>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy(x => x.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); return(services); }
public static void RegisterServices(this IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddHttpClient <IHackerNewsService, HackerNewsService>() .AddPolicyHandler(PollyExtensions.WaitAndTry()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); }
public static void RegisterServices(this IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddHttpClient <IAdapterConsumerServices, AdapterConsumerServices>() .AddPolicyHandler(PollyExtensions.WaitAndTry()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddScoped <IBestStoriesDetailsRepository, BestStoriesDetailsRepository>(); services.AddScoped <IRedisConnection, RedisContext>(); services.AddHostedService <MonitoringHackerNewsHostedService>(); }
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 }
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 <IAutenticacaoService, AutenticacaoService>() .AllowSelfSignedCertificate() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(1, TimeSpan.FromSeconds(30))); services.AddHttpClient <ICatalogoService, CatalogoService>() .AllowSelfSignedCertificate() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(1, TimeSpan.FromSeconds(30))); services.AddHttpClient <IComprasBffService, ComprasBffService>() .AllowSelfSignedCertificate() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(1, TimeSpan.FromSeconds(30))); services.AddHttpClient <IClienteService, ClienteService>() .AllowSelfSignedCertificate() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(1, TimeSpan.FromSeconds(30))); #endregion //services.AddHttpClient("Refit", options => //{ // options.BaseAddress = new Uri(configuration.GetSection("CatalogoUrl").Value); //}) // .AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>() // .AddTypedClient(Refit.RestService.For<ICatalogoServiceRefit>); }
/// <summary> /// Method to configure all HttpClients with Polly Policy /// </summary> /// <param name="services">IServiceCollection</param> /// <param name="configuration">IConfiguration</param> /// <returns>IServiceCollection with HttpClients</returns> public static IServiceCollection ConfigureHttpClients(this IServiceCollection services, IConfiguration configuration) { services.AddHttpClient("Products", client => { client.BaseAddress = new Uri(configuration.GetValue <string>("ProductBaseUrl")); }).AddPolicyHandler(PollyExtensions.ConfigurePolicy()); services.AddHttpClient("Areas", client => { client.BaseAddress = new Uri(configuration.GetValue <string>("AreaBaseUrl")); }).AddPolicyHandler(PollyExtensions.ConfigurePolicy()); services.AddHttpClient("Ingredients", client => { client.BaseAddress = new Uri(configuration.GetValue <string>("IngredientsUrl")); }).AddPolicyHandler(PollyExtensions.ConfigurePolicy()); return(services); }
public static void RegisterServices(this IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAspNetUser, AspNetUser>(); services.AddScoped <ICacheService, CacheService>(); services.AddTransient <HttpClientAuthorizationDelegatingHandler>(); services.AddHttpClient <IUsuarioService, UsuarioService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AllowSelfSignedCertificate() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ISaemService, SaemService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AllowSelfSignedCertificate() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ISafimService, SafimService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AllowSelfSignedCertificate() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ISasciService, SasciService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AllowSelfSignedCertificate() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <ISturService, SturService>() .AddHttpMessageHandler <HttpClientAuthorizationDelegatingHandler>() .AllowSelfSignedCertificate() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); }
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))); }
public static void RegisterServices(this IServiceCollection services, IConfiguration configuration) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IValidationAttributeAdapterProvider, MoedaValidationAttributeAdapterProvider>(); #region HttpServices services.AddHttpClient <ITaxaService, TaxaService>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddHttpClient <IJurosService, JurosService>() .AddPolicyHandler(PollyExtensions.EsperarTentar()) .AllowSelfSignedCertificate() .AddTransientHttpErrorPolicy( p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); #endregion }