-
Notifications
You must be signed in to change notification settings - Fork 585
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
30 lines (25 loc) · 1.14 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
30 lines (25 loc) · 1.14 KB
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
using ExchangeRateUpdater.Api.Application.Interfaces;
using ExchangeRateUpdater.Api.Application.Services;
using ExchangeRateUpdater.Api.Infrastructure.Providers.Cnb;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
namespace ExchangeRateUpdater.Api.Application.Extensions;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
services.AddScoped<ExchangeRateProvider>();
services.AddScoped<IExchangeRateProvider>(sp =>
{
var inner = sp.GetRequiredService<ExchangeRateProvider>();
var cache = sp.GetRequiredService<IMemoryCache>();
var logger = sp.GetRequiredService<ILogger<ExchangeRateProviderDecorator>>();
var options = sp.GetRequiredService<IOptions<CnbApiOptions>>().Value;
return new ExchangeRateProviderDecorator(
inner, cache, logger,
TimeSpan.FromMinutes(options.CacheDurationMinutes),
TimeSpan.FromMinutes(options.HistoricalCacheDurationMinutes));
});
return services;
}
}