My project is .net core 2 base, i set context and repository in startup.cs file
services.AddDbContext<DocumentContext>(options => options.UseSqlServer(connection));
services.AddSingleton<IAuthRepository, AuthRepository>();
IAuthRepository file :
public interface IAuthRepository
{
int Login(LoginRequest model);
int Register(RegisterRequest model);
}
AuthRepository file :
private readonly DocumentContext db;
public AuthRepository(DocumentContext context)
{
this.db = context;
}
...
Controller:
private IAuthRepository AuthMethod { get; set; }
public AuthController(IAuthRepository authMethod)
{
this.AuthMethod = authMethod;
}
I get this error
InvalidOperationException: Cannot consume scoped service '...DocumentContext' from singleton '...IAuthRepository'.