Additional Diagnostics in Dependency Injection (#56809)
authorEric Erhardt <eric.erhardt@microsoft.com>
Sat, 7 Aug 2021 15:21:54 +0000 (10:21 -0500)
committerGitHub <noreply@github.com>
Sat, 7 Aug 2021 15:21:54 +0000 (10:21 -0500)
commit4bac6ed6430e3848f2a5146ad9abe560dd65a6f5
treef943548b103e8852b939aff10e1c363c54fcecd9
parente49b9bd7ae706bbcbefc767d6572232acbb20940
Additional Diagnostics in Dependency Injection (#56809)

* Additional Diagnostics in Dependency Injection

Log events when a ServiceProvider is created:

* How many singleton, scoped, transient services?
* Log the list of registrations

Fix #56313

* Add ServiceProvider HashCode to all events.

* Write ServiceProvider information when DependencyInjectionEventSource becomes enabled.

This allows for listeners to attach to a process after it is running, and get the DI information.

* Update new events to use Informational level and to have a Keyword.

* Switch to use WeakReference when holding on to ServiceProviders in DependencyInjectionEventSource.
src/libraries/Microsoft.Extensions.DependencyInjection/src/DependencyInjectionEventSource.cs
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/DynamicServiceProviderEngine.cs
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/Expressions/ExpressionResolverBuilder.cs
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ILEmit/ILEmitResolverBuilder.cs
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceProvider.cs
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/DependencyInjectionEventSourceTests.cs