HostBuilder Class

Definition

A program initialization utility.

public ref class HostBuilder : Microsoft::Extensions::Hosting::IHostBuilder
public class HostBuilder : Microsoft.Extensions.Hosting.IHostBuilder
type HostBuilder = class
    interface IHostBuilder
Public Class HostBuilder
Implements IHostBuilder
Inheritance
HostBuilder
Implements

Constructors

HostBuilder()

Properties

Properties

A central location for sharing state between components during the host building process.

Methods

Build()

Run the given actions to initialize the host. This can only be called once.

ConfigureAppConfiguration(Action<HostBuilderContext,IConfigurationBuilder>)

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.

ConfigureContainer<TContainerBuilder>(Action<HostBuilderContext,TContainerBuilder>)

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

ConfigureHostConfiguration(Action<IConfigurationBuilder>)

Set up the configuration for the builder itself. This will be used to initialize the IHostEnvironment for use later in the build process. This can be called multiple times and the results will be additive.

ConfigureServices(Action<HostBuilderContext,IServiceCollection>)

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

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
UseServiceProviderFactory<TContainerBuilder>(Func<HostBuilderContext,IServiceProviderFactory<TContainerBuilder>>)

Overrides the factory used to create the service provider.

UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder>)

Overrides the factory used to create the service provider.

Extension Methods

Start(IHostBuilder)

Builds and starts the host.

StartAsync(IHostBuilder, CancellationToken)

Builds and starts the host.

ConfigureAppConfiguration(IHostBuilder, Action<IConfigurationBuilder>)

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.

ConfigureContainer<TContainerBuilder>(IHostBuilder, Action<TContainerBuilder>)

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

ConfigureLogging(IHostBuilder, Action<HostBuilderContext,ILoggingBuilder>)

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

ConfigureLogging(IHostBuilder, Action<ILoggingBuilder>)

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

ConfigureServices(IHostBuilder, Action<IServiceCollection>)

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

RunConsoleAsync(IHostBuilder, Action<ConsoleLifetimeOptions>, CancellationToken)

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

RunConsoleAsync(IHostBuilder, CancellationToken)

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

UseConsoleLifetime(IHostBuilder)

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

UseConsoleLifetime(IHostBuilder, Action<ConsoleLifetimeOptions>)

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

UseContentRoot(IHostBuilder, String)

Specify the content root directory to be used by the host.

UseDefaultServiceProvider(IHostBuilder, Action<ServiceProviderOptions>)

Specify the IServiceProvider to be the default one.

UseDefaultServiceProvider(IHostBuilder, Action<HostBuilderContext,ServiceProviderOptions>)

Specify the IServiceProvider to be the default one.

UseEnvironment(IHostBuilder, String)

Specify the environment to be used by the host.

UseSystemd(IHostBuilder)

Sets the host lifetime to SystemdLifetime, provides notification messages for application started and stopping, and configures console logging to the systemd format.

UseWindowsService(IHostBuilder)

Sets the host lifetime to WindowsServiceLifetime, sets the Content Root, and enables logging to the event log with the application name as the default source name.

Applies to