Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:main
base:main
Choose a base branch
Loading
fromfredrikhr:simple-hosting

Conversation

@fredrikhr
Copy link
Contributor

@fredrikhrfredrikhr commentedJul 7, 2024
edited
Loading

  • RemoveInvocationLifetime
    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 theCliConfiguration tonull when usingSystem.CommandLine.Hosting (theUseHost extension method does that as part of its implementation).
  • IntroduceHostedServiceAction, aCliAction that using a .NET Generic Host hosted service as the execution for a CLI action.
    • Originally, one of the issues with using a Hosted Service as the Action for a CLI Command was that the .NET Generic Host does not automatically shutdown when the hosted service completes its execution task (that is by design, as Hosted services generally run in the background for the entire liftetime of the application).
      HostedServiceAction will automatically shut down the .NET Generic Host when the Hosted Service completes its work, i.e. the command finishes.
    • AddCliHostedService, 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 nameBackgroundService as the main handler for a CLI Command.
  • RenameHostingAction toHostingWrapperAction
    • Create a new base classHostingAction and make bothHostingWrapperAction andHostedServiceAction derive from it.
    • Move the logic of creating the Host and starting it part of the base class, theHostingWrapperAction simply wraps the underlying action, whileHostedServiceAction simply deals with waiting for the hosted service to complete.
  • Prepare extension points for using the modern generic host builder introduced in .NET 8.
    .NET 8 introduces theHostApplicationBuilder 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.
    • Add an internal very limited wrapper aroundHostApplicationBuilder that (partially) implementsIHostBuilder.
    • Add a generic type argument to theHostingAction base class that supports multiple different Host builders.
    • Adding this functionality will require a new TFM for theSystem.CommandLine.Hosting library. Current proposed implementation uses#ifdef set up for multi-targeting.
  • Add a publically settableConfigureHost property on theHostingAction base class.
    • Since the newHostedServiceAction 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.
  • Add a newUseHost extension method forAsynchronousCliAction instances that allows for per-command specific Host configuration actions
  • Provide more examples for a complex multi-command set-up inHostedPlayground
    • Show how multipleHostedServiceActions can have their individual command-specificConfigureHost delegates with a shared whole appConfigureHost delegate.
    • Show differences between using just a regularCommandHandler with a method with hosting vs. using aCliHostedService.
  • Add tests for new introduced features in this PR
    • Tests for combiningConfigureHost fromUseHost andHostingAction
    • Tests for usingHostApplicationBuilder
    • Tests forHostedServiceAction

@fredrikhr
Copy link
ContributorAuthor

#2390 shows that there might be a use-case for anUseHost extension method onBindingHandler that would allow to create per-command Host configurations instead of the currentUseHost extension that is applied for the entire configuration.

@fredrikhrfredrikhrforce-pushed thesimple-hosting branch 2 times, most recently fromd77d299 toc5c910fCompareMarch 31, 2025 21:09
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@fredrikhr

[8]ページ先頭

©2009-2025 Movatter.jp