// We shouldn't inject short life services (scoped,transient) via constructor in middleware. // We use middleware injection with Invoke() or InvokeAsync() methods. public async Task InvokeAsync(HttpContext context, GuidGenerator guid, IWeatherForecaster weatherForecaster) // Middleware Injection { var sky = weatherForecaster.GetCurrentWeather().WeatherCondition; _logger.LogInformation("Guid : {0} and Sky will be {1}", guid.Guid, sky); _next.Invoke(context); }
public CachedWeatherForecaster(IWeatherForecaster weatherForecaster, IDistributedCache <CurrentWeatherResult> cache, IOptionsMonitor <ExternalServicesConfig> options) { _weatherForecaster = weatherForecaster; _cache = cache; _minsToCache = options.Get(ExternalServicesConfig.WeatherApi).MinsToCache; }
//this supports dependency injection by allowing the passing of any dependencies to this consuming code when it's constructed. //Since the HomeController now depends on an abstraction defined by the IWeatherForecaster interface, it is now decoupled from changes to the implementation, which gets injected public HomeController(IWeatherForecaster weatherForecaster, IOptions <FeaturesConfiguration> options) { _weatherForecaster = weatherForecaster; //Once bound, you can inject an instance of IOptions of T into any classes which need access to configuration values. _featuresConfiguration = options.Value; }
public HomeController( IWeatherForecaster weatherForecaster, IOptions <FeaturedConfiguration> options) { _weatherForecaster = weatherForecaster; _featuredConfiguration = options.Value; }
public HomeController( IWeatherForecaster weatherForecaster, IOptions <FeaturesConfiguration> featuresConfiguration) { _weatherForecaster = weatherForecaster; _featuresConfiguration = featuresConfiguration.Value; }
public HomeController(IWeatherForecaster weatherForecaster, IOptions <FeaturesConfiguration> options, ILogger <HomeController> logger) { _weatherForecaster = weatherForecaster; _featuresConfiguration = options.Value; _logger = logger; }
public WeatherForecastController( ILogger <WeatherForecastController> logger, IWeatherForecaster weatherForecaster ) { _logger = logger; _weatherForecaster = weatherForecaster; }
public DegreeCacheService(IWeatherForecaster weatherForecaster, IDistributedCache <WeatherResult> cache, ILogger <DegreeCacheService> logger) { _weatherForecaster = weatherForecaster; _cache = cache; _logger = logger; }
public IndexModel( IWeatherForecaster weatherForecaster, IGreetingService greetingService, IConfiguration configuration) { _weatherForecaster = weatherForecaster; _greetingService = greetingService; _configuration = configuration; }
public IndexModel( IWeatherForecaster weatherForecaster, IOptions <FeaturesConfiguration> options, IHomePageGreetingService greetingService) { _weatherForecaster = weatherForecaster; _greetingService = greetingService; _featuresConfiguration = options.Value; }
public IndexModel(IGreetingService greetingService, IOptionsSnapshot <HomePageConfiguration> options, IWeatherForecaster weatherForecaster) { _greetingService = greetingService; _homePageConfiguration = options.Value; _weatherForecaster = weatherForecaster; GreetingColor = _greetingService.GreetingColor ?? "black"; }
public IndexModel(IWeatherForecaster weatherForecaster, IGreetingService greetingService, IProductsApiClient productsApiClient, IOptionsSnapshot <HomePageConfiguration> options) { _weatherForecaster = weatherForecaster; _greetingService = greetingService; _productsApiClient = productsApiClient; _homePageConfig = options.Value; GreetingColour = _greetingService.GreetingColour ?? "black"; }
public HomeController(IWeatherForecaster weatherForecaster, IOptionsSnapshot <FeaturesConfiguration> options, // If we use IOptionsSnapshot, the configuration registered with scoped not singleton. //GuidGenerator guidGenerator, ILogger <HomeController> logger, IDistributedCache <WeatherResult> cache, IOptionsMonitor <SecondFeaturesConfiguration> secondFeatures) { _weatherForecaster = weatherForecaster; _featuresConfiguration = options.Value; // _guidGenerator = guidGenerator; _logger = logger; _cache = cache; _secondFeatures = secondFeatures.CurrentValue; // IOptionsMonitor also provide us OnChange() method. secondFeatures.OnChange(config => { _secondFeatures = config; _logger.LogInformation("The greeting configuration has been updated."); }); }
public HomeModel(IWeatherForecaster weatherForecaster, IOptions <FeaturesConfiguration> options) { HomeView = new HomeViewModel(); this._weatherForecaster = weatherForecaster; this._featuresConfiguration = options; }
public CachedWeatherForecaster(IWeatherForecaster weatherForecaster, IDistributedCache <CurrentWeatherResult> cache) { _weatherForecaster = weatherForecaster; _cache = cache; }
public LoggingWeatherForecaster(IWeatherForecaster weatherForecaster, ILogger <IWeatherForecaster> logger) { _weatherForecaster = weatherForecaster; _logger = logger; }
public void AddForecaster(IWeatherForecaster observer) { Forecaster.Add(observer); }
/// <summary> /// Initializes a new instance of the <see cref="WeatherForecastController"/> class. /// </summary> /// <param name="weatherService">Data access service.</param> /// <param name="logger">Default logger.</param> public WeatherForecastController(IWeatherForecaster weatherService, ILogger <WeatherForecastController> logger) { _logger = logger; _weatherService = weatherService; }
public HomeController(IWeatherForecaster weatherForecaster) { _weatherForecaster = weatherForecaster; }
public WeatherBot(IVkApi vkApi, IWeatherForecaster weatherForecaster) { VkApi = vkApi; WeatherForecaster = weatherForecaster; }
public WeatherForecastController(IWeatherForecaster forecaster) { _forecaster = forecaster; }
public FisherMan(IAlarmService alarmService = null, IWeatherForecaster weatherForecaster = null) { _alarmService = alarmService; _weatherForecaster = weatherForecaster; }