using Microsoft.Extensions.DependencyInjection;publicclassSampleClass{[Inject]publicILogger<SampleClass> logger {get;set;}publicSampleClass(IServiceProviderprovider)// need IServiceProvider for auto resolve props=> provider.InjectFor(this);}// in DI configure
services.AddScoped<SampleClass>();// or etc lifetime
Mvc usage or etc
using Microsoft.AspNetCore.Mvc;using Microsoft.Extensions.DependencyInjection;publicabstractclassMyGreatSuperWebController:Controller{protectedMyGreatSuperWebController(IServiceProviderprovider)=> provider.InjectFor(this);}// in other controllerspublicclassWeatherController:MyGreatSuperWebController{publicWeatherController(IServiceProviderprovider):base(provder){}[Inject]protectedILogger<WeatherController> logger {get;set;}[Inject]protectedmyBeautifulDbContext{get;set;}publicasyncTask<IActionResult>ViewWeather([FromQuery]stringlocation){
logger.LogInformation($"call ViewWeather with location '{location}' 💫!!1");return View(await myBeautifulDbContext.Set<Weather>().ToListAsync());}}