When I try to run my app I get the error
InvalidOperationException: Cannot resolve \'API.Domain.Data.Repositories.IEmailRepository\' from root provider beca
Middleware is always a singleton so you can't have scoped dependencies as constructor dependencies in the constructor of your middleware.
Middleware supports method injection on the Invoke method,so you can just add the IEmailRepository emailRepository as a parameter to that method and it will be injected there and will be fine as scoped.
public async Task Invoke(HttpContext context, IEmailRepository emailRepository)
{
....
}