コード例 #1
0
        // 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);
        }
コード例 #2
0
 public CachedWeatherForecaster(IWeatherForecaster weatherForecaster,
                                IDistributedCache <CurrentWeatherResult> cache, IOptionsMonitor <ExternalServicesConfig> options)
 {
     _weatherForecaster = weatherForecaster;
     _cache             = cache;
     _minsToCache       = options.Get(ExternalServicesConfig.WeatherApi).MinsToCache;
 }
コード例 #3
0
        //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;
        }
コード例 #4
0
 public HomeController(
     IWeatherForecaster weatherForecaster,
     IOptions <FeaturedConfiguration> options)
 {
     _weatherForecaster     = weatherForecaster;
     _featuredConfiguration = options.Value;
 }
コード例 #5
0
 public HomeController(
     IWeatherForecaster weatherForecaster,
     IOptions <FeaturesConfiguration> featuresConfiguration)
 {
     _weatherForecaster     = weatherForecaster;
     _featuresConfiguration = featuresConfiguration.Value;
 }
コード例 #6
0
 public HomeController(IWeatherForecaster weatherForecaster,
                       IOptions <FeaturesConfiguration> options,
                       ILogger <HomeController> logger)
 {
     _weatherForecaster     = weatherForecaster;
     _featuresConfiguration = options.Value;
     _logger = logger;
 }
コード例 #7
0
 public WeatherForecastController(
     ILogger <WeatherForecastController> logger,
     IWeatherForecaster weatherForecaster
     )
 {
     _logger            = logger;
     _weatherForecaster = weatherForecaster;
 }
コード例 #8
0
 public DegreeCacheService(IWeatherForecaster weatherForecaster,
                           IDistributedCache <WeatherResult> cache,
                           ILogger <DegreeCacheService> logger)
 {
     _weatherForecaster = weatherForecaster;
     _cache             = cache;
     _logger            = logger;
 }
コード例 #9
0
 public IndexModel(
     IWeatherForecaster weatherForecaster,
     IGreetingService greetingService,
     IConfiguration configuration)
 {
     _weatherForecaster = weatherForecaster;
     _greetingService   = greetingService;
     _configuration     = configuration;
 }
コード例 #10
0
 public IndexModel(
     IWeatherForecaster weatherForecaster,
     IOptions <FeaturesConfiguration> options,
     IHomePageGreetingService greetingService)
 {
     _weatherForecaster     = weatherForecaster;
     _greetingService       = greetingService;
     _featuresConfiguration = options.Value;
 }
コード例 #11
0
        public IndexModel(IGreetingService greetingService, IOptionsSnapshot <HomePageConfiguration> options,
                          IWeatherForecaster weatherForecaster)
        {
            _greetingService       = greetingService;
            _homePageConfiguration = options.Value;
            _weatherForecaster     = weatherForecaster;

            GreetingColor = _greetingService.GreetingColor ?? "black";
        }
コード例 #12
0
        public IndexModel(IWeatherForecaster weatherForecaster, IGreetingService greetingService,
                          IProductsApiClient productsApiClient,
                          IOptionsSnapshot <HomePageConfiguration> options)

        {
            _weatherForecaster = weatherForecaster;
            _greetingService   = greetingService;
            _productsApiClient = productsApiClient;
            _homePageConfig    = options.Value;

            GreetingColour = _greetingService.GreetingColour ?? "black";
        }
コード例 #13
0
        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.");
            });
        }
コード例 #14
0
 public HomeModel(IWeatherForecaster weatherForecaster, IOptions <FeaturesConfiguration> options)
 {
     HomeView = new HomeViewModel();
     this._weatherForecaster     = weatherForecaster;
     this._featuresConfiguration = options;
 }
コード例 #15
0
 public CachedWeatherForecaster(IWeatherForecaster weatherForecaster,
                                IDistributedCache <CurrentWeatherResult> cache)
 {
     _weatherForecaster = weatherForecaster;
     _cache             = cache;
 }
コード例 #16
0
 public LoggingWeatherForecaster(IWeatherForecaster weatherForecaster, ILogger <IWeatherForecaster> logger)
 {
     _weatherForecaster = weatherForecaster;
     _logger            = logger;
 }
コード例 #17
0
 public void AddForecaster(IWeatherForecaster observer)
 {
     Forecaster.Add(observer);
 }
コード例 #18
0
 /// <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;
 }
コード例 #19
0
 public HomeController(IWeatherForecaster weatherForecaster)
 {
     _weatherForecaster = weatherForecaster;
 }
コード例 #20
0
 public WeatherBot(IVkApi vkApi, IWeatherForecaster weatherForecaster)
 {
     VkApi             = vkApi;
     WeatherForecaster = weatherForecaster;
 }
コード例 #21
0
 public WeatherForecastController(IWeatherForecaster forecaster)
 {
     _forecaster = forecaster;
 }
コード例 #22
0
 public FisherMan(IAlarmService alarmService = null, IWeatherForecaster weatherForecaster = null)
 {
     _alarmService      = alarmService;
     _weatherForecaster = weatherForecaster;
 }