Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
InvocationLifetime
Originally,
System.CommandLine.Hosting
was designed to depend only onMicrosoft.Extensions.Hosting.Abstractions
which made theInvocationLifetime
class necessary. Currently however, the library depends on the fullMicrosoft.Extensions.Hosting
library, soInvocationLifetime
is no longer required as the functionality of theConsoleLifetime
class fully (and more extensively) covers its functionality.We should however provide guidance that you want set the process termination timeout of the
CliConfiguration
tonull
when usingSystem.CommandLine.Hosting
(theUseHost
extension method does that as part of its implementation).HostedServiceAction
, aCliAction
that using a .NET Generic Host hosted service as the execution for a CLI action.HostedServiceAction
will automatically shut down the .NET Generic Host when the Hosted Service completes its work, i.e. the command finishes.CliHostedService
, a simple derivison fromBackgroundService
, which provides aCliAsyncAction
-similar abstractInvokeAsync
method to override which also allows returning back an integer result value.HostedServiceAction
will use the return value fromCliHostedService
to return the result integer for the invocation.This class also avoids confusion regarding the name
BackgroundService
as the main handler for a CLI Command.HostingAction
toHostingWrapperAction
HostingAction
and make bothHostingWrapperAction
andHostedServiceAction
derive from it.HostingWrapperAction
simply wraps the underlying action, whileHostedServiceAction
simply deals with waiting for the hosted service to complete..NET 8 introduces the
HostApplicationBuilder
class as an alternative to theHostBuilder
andIHostBuilder
interfaces. Annoyingly, theHostApplicationBuilder
does not implement theIHostBuilder
interface necessary for the original implementation of theSystem.CommandLine.Hosting
extensions.HostApplicationBuilder
that (partially) implementsIHostBuilder
.HostingAction
base class that supports multiple different Host builders.System.CommandLine.Hosting
library. Current proposed implementation uses#ifdef
set up for multi-targeting.ConfigureHost
property on theHostingAction
base class.HostedServiceAction
is publically exposed and constructable is is useful to be able to allow for per-command separate ConfigureHost methods.UseHost
will now combine itsconfigureHost
argument with already existingConfigureHost
delegates that have previously been set onHostingActions
set for Cli commands in the CLI configuration.UseHost
extension method forAsynchronousCliAction
instances that allows for per-command specific Host configuration actionsHostedPlayground
HostedServiceActions
can have their individual command-specificConfigureHost
delegates with a shared whole appConfigureHost
delegate.CommandHandler
with a method with hosting vs. using aCliHostedService
.ConfigureHost
fromUseHost
andHostingAction
HostApplicationBuilder
HostedServiceAction