When using the generic .AddSingleton<TService>()
method (and .AddSingleton<TService, TImplementation>()
, the type is created, controlled, and disposed of by the container. When the constructor contains other dependencies, those dependencies are automatically injected (a technique called "Auto-Wiring").
Instances supplied using .AddSingleton<TService>(TService)
already exist. In that case, the container will not dispose of that instance when it implements IDisposable
or IAsyncDisposable
. You are responsible for disposing of that instance yourself.
Since .AddSingleton<TService>(TService)
is supplied with an already existing instance, the container can't inject any dependencies, because in order to do that, it must also create the instance.