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.
  
    
  
    
InvocationLifetimeOriginally,
System.CommandLine.Hostingwas designed to depend only onMicrosoft.Extensions.Hosting.Abstractionswhich made theInvocationLifetimeclass necessary. Currently however, the library depends on the fullMicrosoft.Extensions.Hostinglibrary, soInvocationLifetimeis no longer required as the functionality of theConsoleLifetimeclass fully (and more extensively) covers its functionality.We should however provide guidance that you want set the process termination timeout of the
CliConfigurationtonullwhen usingSystem.CommandLine.Hosting(theUseHostextension method does that as part of its implementation).HostedServiceAction, aCliActionthat using a .NET Generic Host hosted service as the execution for a CLI action.HostedServiceActionwill 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 abstractInvokeAsyncmethod to override which also allows returning back an integer result value.HostedServiceActionwill use the return value fromCliHostedServiceto return the result integer for the invocation.This class also avoids confusion regarding the name
BackgroundServiceas the main handler for a CLI Command.HostingActiontoHostingWrapperActionHostingActionand make bothHostingWrapperActionandHostedServiceActionderive from it.HostingWrapperActionsimply wraps the underlying action, whileHostedServiceActionsimply deals with waiting for the hosted service to complete..NET 8 introduces the
HostApplicationBuilderclass as an alternative to theHostBuilderandIHostBuilderinterfaces. Annoyingly, theHostApplicationBuilderdoes not implement theIHostBuilderinterface necessary for the original implementation of theSystem.CommandLine.Hostingextensions.HostApplicationBuilderthat (partially) implementsIHostBuilder.HostingActionbase class that supports multiple different Host builders.System.CommandLine.Hostinglibrary. Current proposed implementation uses#ifdefset up for multi-targeting.ConfigureHostproperty on theHostingActionbase class.HostedServiceActionis publically exposed and constructable is is useful to be able to allow for per-command separate ConfigureHost methods.UseHostwill now combine itsconfigureHostargument with already existingConfigureHostdelegates that have previously been set onHostingActionsset for Cli commands in the CLI configuration.UseHostextension method forAsynchronousCliActioninstances that allows for per-command specific Host configuration actionsHostedPlaygroundHostedServiceActionscan have their individual command-specificConfigureHostdelegates with a shared whole appConfigureHostdelegate.CommandHandlerwith a method with hosting vs. using aCliHostedService.ConfigureHostfromUseHostandHostingActionHostApplicationBuilderHostedServiceAction