public BnaService(IHttpClientFactory httpClientFactory, HttpClientPoliciesSettings bnaClientPoliciesSettings, BnaSettings bnaSettings, ISlackHooksService slackHooksService) { _httpClient = httpClientFactory.CreateClient(bnaClientPoliciesSettings.ClientName); _bnaSettings = bnaSettings; _slackHooksService = slackHooksService; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var httpClientPolicies = new HttpClientPoliciesSettings(); Configuration.GetSection("HttpClient:BnaClient").Bind(httpClientPolicies); services.AddSingleton(httpClientPolicies); services.AddHttpClient(httpClientPolicies.ClientName, c => { }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)) .AddPolicyHandler(GetRetryPolicy(httpClientPolicies.Policies.RetryAttemps)); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "BNA API", Version = "v1", Description = "API for BNA" }); }); services.AddTransient <IBnaService, BnaService>(); services.AddTransient <ISlackHooksService, SlackHooksService>(); var slackHookSettings = new SlackHookSettings(); Configuration.GetSection("SlackHook").Bind(slackHookSettings); services.AddSingleton(slackHookSettings); var bnaSettings = new BnaSettings(); Configuration.GetSection("BnaService").Bind(bnaSettings); services.AddSingleton(bnaSettings); }