C
C#4mo ago
Kritner

critical mass(?) of service registrations causing scope validation to go from 5 to 30 seconds

does anyone know how to go about looking into why adding one new scoped service registration would cause ValidateScopes going from 5 seconds to 30 seconds at app startup? The registered service itself has a few injected services, which themselves have injected services, etc… On that newly registered service, if i comment out all injected services it goes back down to 5 seconds. I’m not sure really how to go about diagnosing this problem (aside from turning off ValidateScopes in my host builder
12 Replies
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Kritner
KritnerOP4mo ago
I’m not really sure how to do a minimal repro, we have potentially hundreds of services being registered in the di container and it’s this one scoped service that depends on other services that is being an issue 😦
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Becquerel
Becquerel4mo ago
are there any long almost-circular cycles in the services injected into the problematic one? and what is the mix of lifetimes you have? is everything scoped, are some things singletons, etc.? i've not tried this myself personally but you could also try debugging into microsoft.extensions.dependencyinjection if you turn off the Just My Code feature in VS (or whatever the equivalent is in rider etc) also
On that newly registered service, if i comment out all injected services it goes back down to 5 seconds
time to play whack-a-mole on commenting out those services one at a time. see which of the injected ones are causing the problem
SleepWellPupper
SleepWellPupper4mo ago
Does it have a big dependency graph? Cyclic dependencies maybe?
Kritner
KritnerOP4mo ago
is there a way a visually represent the dependency graph? I wouldn't think it would be circular, cuz then it wouldn't validate at all right? we certainly have a mixture of scopes, probably 90% of which are request scoped though, including the newer service and the dependencies within that service (though i haven't checked deeper than that single level)
Becquerel
Becquerel4mo ago
i don't think there is a visual representation, unfortunately. i would find it highly useful for debugging and yeah circular references would just throw an exception i'm 90% sure it would be interesting to see what happens if you converted everything to be singletons/transient because in that case the scope validation should be trivial and if there's still a slowdown you know there's something weird about a specific class, not so much the lifetimes involved
Becquerel
Becquerel4mo ago
out of curiosity i asked AI if it could cook something like this up, and it seems to have delivered: https://pastebin.com/nMYHuMY3
Pastebin
using Microsoft.Extensions.DependencyInjection;using System;using S...
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.
Becquerel
Becquerel4mo ago
No description
Becquerel
Becquerel4mo ago
doesn't seem perfect, but might be useful
SleepWellPupper
SleepWellPupper4mo ago
I use Simpleinjector which ootb supports object graph visualization, It's extremely useful. Maybe there's a library out there that does it for IServiceCollection, too
Kritner
KritnerOP4mo ago
Cool thanks I’ll give this a look and see if anything obviously problematic comes out of it Lmao oom trying to run the graph parsing code Even breaking up into separate string builders in the highest level enumeration 😅
Want results from more Discord servers?
Add your server