I have below folder structure in the .Net 6 worker service with EF 6,
Solution file(.sln)||_ Data(.csproj)| |_ Models| | |_ DatadbContext.cs| || |_ Repository| |_ DbRepository.cs| |_ IDbRepository.cs||_ Service(.csproj) |_ Program.cs |_ Worker.cs
In my Program.cs, I have the service configuration as below for dbContext,
services.AddDbContextPool<DatadbContext>(options => options.UseSqlServer(“connectionStringValue”));
Similarly when I try to configure the Repository in the services(repository project reference added in the service project)
services.AddSingelton<IDbRepository, DbRepository>();
On running the application I am getting the below exception
Cannot consume scoped service “Data.Models.DbContext” from singleton “Data.Repository.DbRepository”
I tried configuring Repository as scoped still got the same exception message.
How to add the repository Dependency so the worker service can receive scoped service in constructor