- Notifications
You must be signed in to change notification settings - Fork412
Refactor Hosting extensions#2450
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
fredrikhr wants to merge5 commits intodotnet:mainChoose a base branch fromfredrikhr:simple-hosting
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Draft
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This was referencedJul 7, 2024
Open
#2390 shows that there might be a use-case for an |
d77d299 toc5c910fCompareSign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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.
Uh oh!
There was an error while loading.Please reload this page.
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