public WeatherForecastController( IWeatherFocaster weatherFocaster, ILogger <WeatherForecastController> logger, // DI Container will resolve all instances of IRule and inject them as an IEnumerable. IEnumerable <IRule> rules ) { _weatherFocaster = weatherFocaster; _logger = logger; _rules = rules; }
// Action Injection: injecting the services into an Action Method. The services is resolved only when this endpoint is called // and not when this controller class is created (as it will be creating all the dependecies injected through its Ctor). public IActionResult Get([FromServices] IWeatherFocaster weather) { var season = weather.GetSeason(); return(Ok(season)); }