-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMSSenderExtension.cs
32 lines (25 loc) · 983 Bytes
/
SMSSenderExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using Microsoft.Extensions.DependencyInjection;
using Polly;
namespace SMSSender
{
public static class SMSSenderExtension
{
public static IServiceCollection AddSMSSenderServices(this IServiceCollection services, Action<SMSSenderOptions> setupAction)
{
if (setupAction != null)
{
services.Configure(setupAction);
}
services.AddTransient<HttpClientDelegatingHandler>();
services.AddHttpClient<ISMSSender, SMSSender>(option =>
{
option.DefaultRequestHeaders.Add("Conetent-Type", "application/json");
})
.AddHttpMessageHandler<HttpClientDelegatingHandler>()
.AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(600)))
.AddTransientHttpErrorPolicy(p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(10)));
return services;
}
}
}