Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

.Net 6 worker service EF 6 - Repository DI cannot consume scoped service

$
0
0

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


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>