Fire diagnostic source events from IHostBuilder.Build (#53757)
authorDavid Fowler <davidfowl@gmail.com>
Tue, 8 Jun 2021 15:47:49 +0000 (08:47 -0700)
committerGitHub <noreply@github.com>
Tue, 8 Jun 2021 15:47:49 +0000 (08:47 -0700)
commit543a983671252751e3c8128f0e359e8b551e0998
tree6166c43392c24d50727e49926d1189d11a1ed7bc
parent9af4b97f89b99ac111ae1dbcef7071d74f00330c
Fire diagnostic source events from IHostBuilder.Build (#53757)

* Fire diagnostic source events from IHostBuilder.Build
- We want to enable getting access to the IHostBuilder and IHost during the call to IHostBuilder.Build so that we can access the application's IServiceProvider from various tools. Usually, this is enabled by exposing a different entry point from the application but this technique allows us to let the application execute normally and hook important events via a diagnostic source.
- Add support for the new pattern in HostFactoryResolver
- Added support for resolving an IServiceProvider using the new diagnostics source pattern (which doesn't require a different entrypoint)
- Detect the version of Microsoft.Extensions.Hosting before waiting for events to fire
- We want to fail fast if we know this version of hosting will never fire events of if the hosting assembly fails to load. Added a version check.
- Allow the caller to specify a wait timeout.
-  Added a flag to allow running the application to completion
22 files changed:
src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/CreateHostBuilderInvalidSignature/Program.cs
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/CreateHostBuilderPatternTestSite/Program.cs
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/MockHostTypes/HostBuilder.cs [deleted file]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/MockHostTypes/MockHostTypes.csproj
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPattern/NoSpecialEntryPointPattern.csproj [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPattern/Program.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternExits/NoSpecialEntryPointPatternExits.csproj [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternExits/Program.cs [moved from src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/MockHostTypes/Host.cs with 53% similarity]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternHangs/NoSpecialEntryPointPatternHangs.csproj [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternHangs/Program.cs [moved from src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/MockHostTypes/IHost.cs with 50% similarity]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternMainNoArgs/NoSpecialEntryPointPatternMainNoArgs.csproj [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternMainNoArgs/Program.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternThrows/NoSpecialEntryPointPatternThrows.csproj [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/NoSpecialEntryPointPatternThrows/Program.cs [new file with mode: 0644]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/TopLevelStatements/Program.cs [moved from src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/MockHostTypes/IHostBuilder.cs with 58% similarity]
src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/TopLevelStatements/TopLevelStatements.csproj [new file with mode: 0644]
src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Microsoft.Extensions.Hosting.Unit.Tests.csproj