public CachedCoinmarketCapService(ICryptoCurrencyExchangeService cryptoCurrencyExchangeService,
                                   CoinmarketCapConfig coinmarketCapConfig)
 {
     _cryptoCurrencyExchangeService = cryptoCurrencyExchangeService;
     _coinmarketCapConfig           = coinmarketCapConfig;
     _cache = new ConcurrentDictionary <string, CachedCryptoCurrency>();
 }
Exemple #2
0
        public static void ConfigureInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDbContext <CryptoCurrencyContext>(option => option.UseInMemoryDatabase("knab-cryptocurrency-in-memory-db"));

            var coinmarketCapOptions = new CoinmarketCapConfig();

            configuration.Bind(nameof(CoinmarketCapConfig), coinmarketCapOptions);
            services.AddSingleton(coinmarketCapOptions);

            services.AddTransient <ICryptoCurrencyRepository, CryptoCurrencyRepository>();

            services.AddSingleton <ICryptoCurrencyExchangeService, CoinmarketCapService>();
            services.Decorate <ICryptoCurrencyExchangeService, CachedCoinmarketCapService>();
        }