Skip to content

Commit 13f6b87

Browse files
committed
Remove InvocationLifetime class
1 parent ad4ebc9 commit 13f6b87

File tree

4 files changed

+6
-119
lines changed

4 files changed

+6
-119
lines changed

src/System.CommandLine.Hosting/HostingAction.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public override async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio
5050
?? new HostBuilder();
5151
hostBuilder.Properties[typeof(ParseResult)] = parseResult;
5252

53+
// As long as done before first await,
54+
// we can set the process termination timeout to null
55+
// and let the .NET Host ConsoleLifetime deal with termination
56+
parseResult.Configuration.ProcessTerminationTimeout = null;
57+
hostBuilder.UseConsoleLifetime();
58+
5359
if (parseResult.Configuration.RootCommand is RootCommand root &&
5460
root.Directives.SingleOrDefault(d => d.Name == HostingDirectiveName) is { } directive)
5561
{
@@ -72,7 +78,6 @@ public override async Task<int> InvokeAsync(ParseResult parseResult, Cancellatio
7278

7379
var bindingContext = GetBindingContext(parseResult);
7480
int registeredBefore = 0;
75-
hostBuilder.UseInvocationLifetime();
7681
hostBuilder.ConfigureServices(services =>
7782
{
7883
services.AddSingleton(parseResult);

src/System.CommandLine.Hosting/HostingExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ public static CommandLineConfiguration UseHost(
3131
Action<IHostBuilder> configureHost = null
3232
) => UseHost(config, null, configureHost);
3333

34-
public static IHostBuilder UseInvocationLifetime(this IHostBuilder host, Action<InvocationLifetimeOptions> configureOptions = null)
35-
{
36-
return host.ConfigureServices(services =>
37-
{
38-
services.AddSingleton<IHostLifetime, InvocationLifetime>();
39-
if (configureOptions is Action<InvocationLifetimeOptions>)
40-
services.Configure(configureOptions);
41-
});
42-
}
43-
4434
public static OptionsBuilder<TOptions> BindCommandLine<TOptions>(
4535
this OptionsBuilder<TOptions> optionsBuilder)
4636
where TOptions : class

src/System.CommandLine.Hosting/InvocationLifetime.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/System.CommandLine.Hosting/InvocationLifetimeOptions.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)