IHostBuilder 介面

定義

程式初始化的抽象概念。A program initialization abstraction.

public interface class IHostBuilder
public interface IHostBuilder
type IHostBuilder = interface
Public Interface IHostBuilder
衍生

屬性

Properties

在主機組建流程期間,於元件之間共用狀態的中央位置。A central location for sharing state between components during the host building process.

方法

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. 這些結果可用於後續作業的 Configuration,以及 ServicesThe 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. 這將用來初始化 IHostEnvironment,以供稍後在組建流程中使用。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.

UseServiceProviderFactory<TContainerBuilder>(Func<HostBuilderContext,IServiceProviderFactory<TContainerBuilder>>)

覆寫用來建立服務提供者的 Factory。Overrides the factory used to create the service provider.

UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder>)

覆寫用來建立服務提供者的 Factory。Overrides the factory used to create the service provider.

擴充方法

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. 這些結果可用於後續作業的 Configuration,以及 ServicesThe 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>)

新增用於設定所提供 ILoggingBuilder 的委派。Adds a delegate for configuring the provided ILoggingBuilder. 可能會多次呼叫此項。This may be called multiple times.

ConfigureLogging(IHostBuilder, Action<ILoggingBuilder>)

新增用於設定所提供 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)

啟用主控台支援、建置和啟動主機,以及等候 Ctrl+C 或 SIGTERM 關機。Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

RunConsoleAsync(IHostBuilder, CancellationToken)

啟用主控台支援、建置和啟動主機,以及等候 Ctrl+C 或 SIGTERM 關機。Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

UseConsoleLifetime(IHostBuilder)

接聽 Ctrl+C 或 SIGTERM,並呼叫 StopApplication() 以啟動關機流程。Listens for Ctrl+C or SIGTERM and calls StopApplication() to start the shutdown process. 這會解除封鎖 RunAsync 和 WaitForShutdownAsync 等延伸模組。This will unblock extensions like RunAsync and WaitForShutdownAsync.

UseConsoleLifetime(IHostBuilder, Action<ConsoleLifetimeOptions>)

接聽 Ctrl+C 或 SIGTERM,並呼叫 StopApplication() 以啟動關機流程。Listens for Ctrl+C or SIGTERM and calls StopApplication() to start the shutdown process. 這會解除封鎖 RunAsync 和 WaitForShutdownAsync 等延伸模組。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>)

IServiceProvider 指定為預設值。Specify the IServiceProvider to be the default one.

UseDefaultServiceProvider(IHostBuilder, Action<HostBuilderContext,ServiceProviderOptions>)

IServiceProvider 指定為預設值。Specify the IServiceProvider to be the default one.

UseEnvironment(IHostBuilder, String)

指定主機要使用的環境。Specify the environment to be used by the host.

UseSystemd(IHostBuilder)

將主機存留期設定為 SystemdLifetime、提供應用程式啟動和停止的通知訊息,以及將主控台記錄設定為 systemd 格式。Sets the host lifetime to SystemdLifetime, provides notification messages for application started and stopping, and configures console logging to the systemd format.

UseWindowsService(IHostBuilder)

將主機存留期設定為 WindowsServiceLifetime、設定內容根目錄,以及啟用記錄至事件記錄檔功能,並以應用程式名稱作為預設來源名稱。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.

適用於