Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            //services.AddOptions();

            //services.Configure<WeatherCacheSettings>(Configuration);
            //services.Configure<WeatherAPISettings>(Configuration.GetSection("WeatherAPISettings"));

            var configWeatherCacheSettings = new WeatherCacheSettings();

            Configuration.Bind("WeatherCacheSettings", configWeatherCacheSettings);
            services.AddSingleton(configWeatherCacheSettings);

            var configWeatherApiSettings = new WeatherAPISettings();

            Configuration.Bind("WeatherAPISettings", configWeatherApiSettings);
            services.AddSingleton(configWeatherApiSettings);

            services.AddMemoryCache();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddScoped(typeof(IWeatherDataCache), typeof(WeatherDataCache));
            services.AddScoped(typeof(IJsonParsor), typeof(JsonParsor));
            services.AddScoped(typeof(IWeatherService), typeof(WeatherService));
            services.AddScoped(typeof(IRegionsRepository), typeof(RegionsRepository));
            services.AddScoped(typeof(IWeatherRepository), typeof(WeatherRepository));
        }
Exemplo n.º 2
0
 public WeatherDataCache(WeatherCacheSettings cacheSettings, IMemoryCache memoryCache)
 {
     _cacheSettings = cacheSettings;
     _cache         = memoryCache;
 }