Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire diagnostic source events from IHostBuilder.Build #53757

Merged
merged 17 commits into from
Jun 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Store the entrypoint directly
  • Loading branch information
davidfowl committed Jun 6, 2021
commit 08729fe074327e554c938e5fa30f4608f74fabed
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal sealed class HostFactoryResolver
return null;
}

return args => new DeferredHostBuilder(args, assembly);
return args => new DeferredHostBuilder(args, assembly.EntryPoint);
}

private static Func<string[], T>? ResolveFactory<T>(Assembly assembly, string name)
Expand Down Expand Up @@ -147,7 +147,7 @@ private class DeferredHostBuilder : IHostBuilder, IObserver<DiagnosticListener>,
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();

private readonly string[] _args;
private readonly Assembly _assembly;
private readonly MethodInfo _entryPoint;

private readonly TaskCompletionSource<IHost> _hostTcs = new();
private IDisposable? _disposable;
Expand All @@ -157,10 +157,10 @@ private class DeferredHostBuilder : IHostBuilder, IObserver<DiagnosticListener>,
// The amount of time we wait for the diagnostic source events to fire
private static readonly TimeSpan _waitTimeout = TimeSpan.FromSeconds(5);
davidfowl marked this conversation as resolved.
Show resolved Hide resolved

public DeferredHostBuilder(string[] args, Assembly assembly)
public DeferredHostBuilder(string[] args, MethodInfo entryPoint)
{
_args = args;
_assembly = assembly;
_entryPoint = entryPoint;
_configure = b =>
davidfowl marked this conversation as resolved.
Show resolved Hide resolved
{
// Copy the properties from this builder into the builder
Expand All @@ -182,14 +182,14 @@ public IHost Build()
{
try
{
var parameters = _assembly.EntryPoint!.GetParameters();
var parameters = _entryPoint.GetParameters();
if (parameters.Length == 0)
{
_assembly.EntryPoint!.Invoke(null, Array.Empty<object>());
_entryPoint.Invoke(null, Array.Empty<object>());
}
else
{
_assembly.EntryPoint!.Invoke(null, new object[] { _args });
_entryPoint.Invoke(null, new object[] { _args });
}

// Try to set an exception if the entrypoint returns gracefully, this will force
Expand Down