コード例 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Exchange Rate Api", Version = "v1"
                });
            });

            var configuration = new ExchangeRateServiceConfiguration()
            {
                StorageFolderPath = Path.Combine(Path.GetTempPath(), "ExchangeRates"),
                CacheDuration     = new TimeSpan(0, 0, 5, 0)
            };

            services.AddSingleton <IDataFeedRepositoryConfiguration>(configuration);
            services.AddSingleton(configuration);
            services.AddTransient <IDataFeedRepository, DataFeedRepository>();
            services.AddTransient <IDataFeedMapper, DataFeedMapper>();
            services.AddTransient <IDataFeedService, DataFeedServiceWithCache>();
            services.AddTransient <DataFeedService, DataFeedService>();

            services.AddMemoryCache();
        }
コード例 #2
0
 public DataFeedServiceWithCache(
     DataFeedService dataFeedService,
     IMemoryCache memoryCache,
     ExchangeRateServiceConfiguration configuration)
 {
     this.dataFeedService = dataFeedService ?? throw new ArgumentNullException(nameof(dataFeedService));
     this.memoryCache     = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));
     this.configuration   = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }