Table of Contents

Method ConfigureHost

Namespace
Ploch.CommandLine.Spectre
Assembly
Ploch.CommandLine.Spectre.dll

ConfigureHost(Action<IHostBuilder>)

Configures the host builder for the application.

[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = "This method is a part of the public API and is intended for use by consumers of the AppBuilder class.")]
public AppBuilder ConfigureHost(Action<IHostBuilder> configureDelegate)

Parameters

configureDelegate Action<IHostBuilder>

A delegate that provides custom configuration for the IHostBuilder.

Returns

AppBuilder

The current instance of AppBuilder for method chaining.

Remarks

This method allows customisation of the application's host builder, enabling the addition of services, configuration, and other host-level settings. It integrates with the Microsoft.Extensions.Hosting framework.

Calls accumulate: every delegate is applied to the host builder, in the order it was added. That order is shared with ConfigureServices(Action<HostBuilderContext, IServiceCollection>) and ConfigureAppConfiguration(Action<HostBuilderContext, IConfigurationBuilder>), so a service this delegate registers through ConfigureServices(Action<HostBuilderContext, IServiceCollection>), or an application configuration source it adds through ConfigureAppConfiguration(Action<HostBuilderContext, IConfigurationBuilder>), takes precedence over one registered by an earlier call to the matching method and yields to one registered by a later call. Other host builder phases keep their own fixed order; see ConfigureCommandApp(Action<IConfigurator>) for the full ordering guarantee.

The host the delegate configures is built once a run reaches command resolution and is never started by the library, so a hosted service registered through it does not run; see ConfigureCommandApp(Action<IConfigurator>).

Exceptions

ArgumentNullException

Thrown when configureDelegate is null.