Ejemplo n.º 1
0
        private static IServiceCollection Add(IServiceCollection services, AppMailClient.Options options)
        {
            services.AddScoped <AppMailClient.Options>(sp => options);

            if (String.IsNullOrEmpty(options?.Url))
            {
                services.AddScoped <IAppMailClient, MailerMock>();
            }
            else
            {
                services.AddScoped <IAppMailClient, Mailer>();

                services.AddHttpClient <IAppMailClient, Mailer>()
                .ConfigureHttpClient(client => {
                    client.BaseAddress = new System.Uri(options.Url);
                    client.DefaultRequestHeaders.Add(options.KeyHeader, options.Key);
                })
                .AddPolicyHandler(
                    HttpPolicyExtensions.HandleTransientHttpError()
                    .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
                    .WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
                    );
            }
            return(services);
        }
Ejemplo n.º 2
0
        public static IServiceCollection AddAppMailClient(this IServiceCollection services, Action <AppMailClient.Options> config)
        {
            var options = new AppMailClient.Options();

            if (config != null)
            {
                config.Invoke(options);
            }

            Add(services, options);

            return(services);
        }