How does Microsoft.Extensions.DependencyInjection resolve a service internally, from AddSingleton to the instance?
AddSingleton only appends a ServiceDescriptor to a list. BuildServiceProvider indexes those descriptors, and the first GetService builds a call-site tree with reflection, caches it, and wraps it in an accessor delegate. Singletons are stored on the call site itself, scoped instances in a per-scope dictionary, and after the second resolve of a non-singleton the container compiles an IL DynamicMethod on the thread pool. Walked through the .NET 11 source and observed with reflection, EventSource events and BenchmarkDotNet.