<PackageReference Include="Microsoft.Extensions.Hosting" Version="11.0.0-preview.7.26381.103" />

Microsoft.Extensions.Hosting.HostingHostBuilderExtensions

public static class HostingHostBuilderExtensions
Provides extension methods for the IHostBuilder from the hosting package.
public static IHostBuilder ConfigureAppConfiguration(this IHostBuilder hostBuilder, Action<IConfigurationBuilder> configureDelegate)

Sets up the configuration for the remainder of the build process and application. This can be called multiple times and the results will be additive. The results will be available at Configuration for subsequent operations, as well as in Services.

public static IHostBuilder ConfigureContainer<TContainerBuilder>(this IHostBuilder hostBuilder, Action<TContainerBuilder> configureDelegate)

Enables configuring the instantiated dependency container. This can be called multiple times and the results will be additive.

public static IHostBuilder ConfigureDefaults(this IHostBuilder builder, string[] args)

Configures an existing IHostBuilder instance with pre-configured defaults. This will overwrite previously configured values and is intended to be called before additional configuration calls.

public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostBuilderContext, HostOptions> configureOptions)

Adds a delegate for configuring the HostOptions of the IHost.

public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureOptions)

Adds a delegate for configuring the HostOptions of the IHost.

public static IHostBuilder ConfigureLogging(this IHostBuilder hostBuilder, Action<HostBuilderContext, ILoggingBuilder> configureLogging)

Adds a delegate for configuring the provided ILoggingBuilder. This can be called multiple times.

public static IHostBuilder ConfigureLogging(this IHostBuilder hostBuilder, Action<ILoggingBuilder> configureLogging)

Adds a delegate for configuring the provided ILoggingBuilder. This can be called multiple times.

public static IHostBuilder ConfigureMetrics(this IHostBuilder hostBuilder, Action<IMetricsBuilder> configureMetrics)

Adds a delegate for configuring the provided IMetricsBuilder. This can be called multiple times.

public static IHostBuilder ConfigureMetrics(this IHostBuilder hostBuilder, Action<HostBuilderContext, IMetricsBuilder> configureMetrics)

Adds a delegate for configuring the provided IMetricsBuilder. This can be called multiple times.

public static IHostBuilder ConfigureServices(this IHostBuilder hostBuilder, Action<IServiceCollection> configureDelegate)

Adds services to the container. This can be called multiple times and the results will be additive.

public static Task RunConsoleAsync(this IHostBuilder hostBuilder, CancellationToken cancellationToken = default)

Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

public static Task RunConsoleAsync(this IHostBuilder hostBuilder, Action<ConsoleLifetimeOptions> configureOptions, CancellationToken cancellationToken = default)

Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

public static IHostBuilder UseConsoleLifetime(this IHostBuilder hostBuilder)

Listens for Ctrl+C or SIGTERM and calls StopApplication to start the shutdown process. This will unblock extensions like RunAsync and WaitForShutdownAsync.

public static IHostBuilder UseConsoleLifetime(this IHostBuilder hostBuilder, Action<ConsoleLifetimeOptions> configureOptions)

Listens for Ctrl+C or SIGTERM and calls StopApplication to start the shutdown process. This will unblock extensions like RunAsync and WaitForShutdownAsync.

public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder, string contentRoot)

Specifies the content root directory to be used by the host. To avoid the content root directory being overwritten by a default value, ensure this is called after defaults are configured.

public static IHostBuilder UseDefaultServiceProvider(this IHostBuilder hostBuilder, Action<ServiceProviderOptions> configure)

Specifies the IServiceProvider to be the default one.

public static IHostBuilder UseDefaultServiceProvider(this IHostBuilder hostBuilder, Action<HostBuilderContext, ServiceProviderOptions> configure)

Specifies the IServiceProvider to be the default one.

public static IHostBuilder UseEnvironment(this IHostBuilder hostBuilder, string environment)

Specifies the environment to be used by the host. To avoid the environment being overwritten by a default value, ensure this is called after defaults are configured.