Skip to content

No UseHost(this CommandLineBuilder builder, Func<string[], HostApplicationBuilder> appBuilderFactory, Action<HostApplicationBuilder> configureAppHost) overload #2097

Description

@fourpastmidnight

Apparently, a relatively recent decision was made to change how application host construction is done. The "old" way was a series of chained method calls on classes that implement the IHostBuilder interface. Apparently, there were issues with that, and so a complete cut was made—a new HostApplicationBuilder class was created which does not implement IHostBuilder.

The current suggested documentation for hosting a Windows Service in .NET Core (https://learn.microsoft.com/en-us-dotnet/core/extensions/windows-service) recommends using something like this:

var hostBuilder = Host.CreateApplicationBuilder();
hostBuilder.Services.AddWindowsService();
hostBuilder.Services.AddSingleton<YourService>();
hostBuilder.Services.AddHostedService<WindowsBackgroundService>();

var host = hostBuilder.Build();
host.Run()

So, translating this into System.CommandLineBuilder, I tried:

var rootCommand = new RootCommand("The root command.");
var commandLineBuilder = new CommandLineBuilder(rootCommand)
    .UseDefaults()
    .UseHost(Host.CreateApplicationBuilder /* BOOM: Not an IHostBuilder!! */, hostBuilder => {
        // Configure your host here...
    })
    .Build();

But as you can see, with the new "recommended" pattern, this fails because there is no overload of UseHost() that accepts an HostApplicationBuilder builder.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions