< Summary

Information
Class: c:\Source 2025\CurrencyConverter\CurrencyConverter\src\Infrastructure\DependencyInjection.cs
Assembly: Default
File(s): c:\Source 2025\CurrencyConverter\CurrencyConverter\src\Infrastructure\DependencyInjection.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 60
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

c:\Source 2025\CurrencyConverter\CurrencyConverter\src\Infrastructure\DependencyInjection.cs

#LineLine coverage
 1using Application.Abstractions;
 2using Domain.Currencies;
 3using Infrastructure.Caching;
 4using Infrastructure.ExchangeProviders;
 5using Infrastructure.ExchangeProviders.Frankfurter;
 6using Infrastructure.Extensions;
 7using Microsoft.Extensions.Configuration;
 8using Microsoft.Extensions.DependencyInjection;
 9using Microsoft.Extensions.Http.Resilience;
 10using Polly;
 11using TimeProvider = Infrastructure.Utilities.TimeProvider;
 12
 13
 14namespace Infrastructure
 15{
 16    public static class DependencyInjection
 17    {
 18        public static IServiceCollection InjectInfrastructure(
 19            this IServiceCollection services,
 20            IConfiguration configuration)
 421        {
 422            services.AddCaching(configuration);
 423            services.AddCurrencyProviders(configuration);
 424            services.AddUtilities();
 425            services.AddAuthentication(configuration);
 426            return services;
 427        }
 28
 29        private static void AddCaching(this IServiceCollection services, IConfiguration configuration)
 430        {
 531            services.AddStackExchangeRedisCache(options => options.Configuration = configuration.GetConnectionString("Ca
 432            services.AddSingleton<ICacheService, CacheService>();
 433        }
 34
 35        public static IServiceCollection AddCurrencyProviders(this IServiceCollection services, IConfiguration configura
 436        {
 437            var baseUrl = configuration["ProviderUrls:FrankfurterBaseUrl"];
 438            services.AddHttpClient<IExchangeProvider, FrankfurterExchangeProvider>(client =>
 139            {
 140                client.BaseAddress = new Uri(baseUrl);
 141            })
 442            .AddStandardResilienceHandler().Configure(x =>
 143            {
 144                x.Retry.MaxRetryAttempts = 3;
 145                x.Retry.Delay = TimeSpan.FromSeconds(1);
 146                x.Retry.UseJitter = true;
 147                x.Retry.BackoffType = DelayBackoffType.Exponential;
 148                x.CircuitBreaker.MinimumThroughput = 10;
 149                x.TotalRequestTimeout.Timeout = TimeSpan.FromSeconds(10);
 550            });
 451            services.AddTransient<IExchangeProviderFactory, ExchangeProviderFactory>();
 452            return services;
 453        }
 54        public static IServiceCollection AddUtilities(this IServiceCollection services)
 455        {
 456            services.AddSingleton<ITimeProvider, TimeProvider>();
 457            return services;
 458        }
 59    }
 60}