Fix some issues with background thread compilation (#42986)
authorMaryam Ariyan <maryam.ariyan@microsoft.com>
Fri, 9 Oct 2020 11:52:46 +0000 (04:52 -0700)
committerGitHub <noreply@github.com>
Fri, 9 Oct 2020 11:52:46 +0000 (04:52 -0700)
commit34eed9ce561a795844b8ed7d1a4ed7fd7d86016c
treeef0d9c62b8dbb9b07339ec9b493a99c6f3dde2cd
parent39e080d5c51f30afb3862de6b805bebd1d24a6f1
Fix some issues with background thread compilation (#42986)

- Resolve dependencies before counting to avoid the race
where its possible for the background thread to run before
the main thread resulting in singletons being resolved during
compilation (it's meant to be side effect free).

- We also avoid capturing the ExecutionContext on the background thread
to avoid capture of async locals.

Fixes dotnet/extensions#3566

Taken from https://github.com/dotnet/extensions/pull/3569/commits/07e4459b6e81d10c9b3a6561f4cc0fe5a6cbcf8b
src/libraries/Microsoft.Extensions.DependencyInjection/src/Microsoft.Extensions.DependencyInjection.csproj
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/DynamicServiceProviderEngine.cs