I have the following controller Class;
public class MyController: Controller { private IValueService _service; public MyController(IValueService se
In Startup file add :
services.AddMvc().AddControllersAsServices();
it will registers all controllers in your application with the DI container.
Then :
var serviceProvider = HttpContext.RequestServices; var controller =(MyController)serviceProvider.GetRequiredService(); controller.Method();