C
C#2y ago
.bobgoblin

❔ DI Question

I have this code for setting up DI in my worker service project https://pastebin.com/6HH5sBAx But when I run my code I get this error
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: WorkerService1.Worker': A circular dependency was detected
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: WorkerService1.Worker': A circular dependency was detected
What have I set-up wrong?
Pastebin
codeu - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
7 Replies
Saber
Saber2y ago
well the error says a circular dependency was detected so thats a pretty clear point to start
.bobgoblin
.bobgoblin2y ago
i checked in program.cs and i didn't see i had set up services... for the same thing twice, so it means something other than what i thought
Saber
Saber2y ago
should probably google it then
.bobgoblin
.bobgoblin2y ago
I tried changing the AddSingleton() to AddTransient() and same error
Saber
Saber2y ago
because that isn't the issue if Foo requires Bar, and Bar requires Foo that is a circular reference
.bobgoblin
.bobgoblin2y ago
ohhh, that get's loaded. Could be a DI problem, could be a code smell
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts