How to do DI in asp.net core middleware?
I am trying to inject dependency into my middleware constructor as follows public class CreateCompanyMiddleware { private readonly RequestDelegate _next; private readonly UserManager<ApplicationUser> _userManager; public CreateCompanyMiddleware(RequestDelegate next , UserManager<ApplicationUser> userManager ) { _next = next; } public async Task Invoke(HttpContext context) { await _next.Invoke(context); } } My Startup.cs file looks like public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ApplicationDbContext>(options => options.UseMySql(Configuration