// 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)); }
public WeatherAPIController(IOptions <WeatherAPISettings> weatherAPISettings) { _weatherAPISettings = weatherAPISettings.Value; }
public WeatherService(WeatherAPISettings apiSettings) { _apiSettings = apiSettings; }
public SimpleRepository(IOptions <WeatherAPISettings> options) { _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); }