HostBuilder 类

定义

程序初始化实用工具。

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
继承
HostBuilder
实现

构造函数

HostBuilder()

初始化 HostBuilder 的新实例。

属性

Properties

用于在主机生成过程中共享组件间状态的中心位置。

方法

Build()

运行给定的操作来初始化主机。 此方法只能调用一次。

ConfigureAppConfiguration(Action<HostBuilderContext,IConfigurationBuilder>)

为生成过程和应用程序的其余部分设置配置。 传入的 Configuration 是通过调用 ConfigureHostConfiguration(Action<IConfigurationBuilder>) 生成的主机配置。 可多次进行调用,并累加结果。 处理所有调用后,将使用结果更新 Configuration 以用于将来的生成步骤。 生成的配置还将存储在 Services DI 容器中供使用。

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

允许配置实例化的依赖项容器。 可多次进行调用,并累加结果。

ConfigureHostConfiguration(Action<IConfigurationBuilder>)

设置生成器自身的配置。 这将用于初始化 IHostEnvironment 以便稍后在生成过程中使用。 可多次进行调用,并累加结果。

ConfigureServices(Action<HostBuilderContext,IServiceCollection>)

向容器添加服务。 可多次进行调用,并累加结果。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
UseServiceProviderFactory<TContainerBuilder>(Func<HostBuilderContext,IServiceProviderFactory<TContainerBuilder>>)

重写用于创建服务提供程序的工厂。

UseServiceProviderFactory<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder>)

重写用于创建服务提供程序的工厂。

扩展方法

UseApplicationMetadata(IHostBuilder, String)

为应用程序元数据注册配置提供程序,并将模型对象绑定到配置。

AddFakeLoggingOutputSink(IHostBuilder, Action<String>)

添加对每条日志消息调用的操作。

Configure(IHostBuilder, Action<IHostBuilder>)

IHostBuilder通过委托公开更改。

ConfigureAppConfiguration(IHostBuilder, String, String)

添加配置值。

ConfigureAppConfiguration(IHostBuilder, ValueTuple<String,String>[])

添加配置条目。

ConfigureHostConfiguration(IHostBuilder, String, String)

添加配置值。

ConfigureHostConfiguration(IHostBuilder, ValueTuple<String,String>[])

添加配置条目。

Start(IHostBuilder)

生成并启动该主机。

StartAsync(IHostBuilder, CancellationToken)

生成并启动该主机。

ConfigureAppConfiguration(IHostBuilder, Action<IConfigurationBuilder>)

为生成过程和应用程序的其余部分设置配置。 可多次进行调用,并累加结果。 可在 Configuration(用于后续操作)和 Services 中获取结果。

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

允许配置实例化的依赖项容器。 可多次进行调用,并累加结果。

ConfigureDefaults(IHostBuilder, String[])

使用预配置的默认值配置现有 IHostBuilder 实例。 这将覆盖以前配置的值,并应在其他配置调用之前调用。

ConfigureHostOptions(IHostBuilder, Action<HostBuilderContext,HostOptions>)

添加一个委托,用于配置 HostOptions 的 。IHost

ConfigureHostOptions(IHostBuilder, Action<HostOptions>)

添加一个委托,用于配置 HostOptions 与 相关的 实例的 IHost

ConfigureLogging(IHostBuilder, Action<HostBuilderContext,ILoggingBuilder>)

添加一个委托来配置提供的 ILoggingBuilder。 这可多次进行调用。

ConfigureLogging(IHostBuilder, Action<ILoggingBuilder>)

添加一个委托来配置提供的 ILoggingBuilder。 这可多次进行调用。

ConfigureMetrics(IHostBuilder, Action<IMetricsBuilder>)

添加一个委托来配置提供的 IMetricsBuilder。 这可多次进行调用。

ConfigureMetrics(IHostBuilder, Action<HostBuilderContext,IMetricsBuilder>)

添加一个委托来配置提供的 IMetricsBuilder。 这可多次进行调用。

ConfigureServices(IHostBuilder, Action<IServiceCollection>)

向容器添加服务。 可多次进行调用,并累加结果。

RunConsoleAsync(IHostBuilder, Action<ConsoleLifetimeOptions>, CancellationToken)

启用控制台支持、生成和启动主机,并等待 Ctrl+C 或 SIGTERM 关闭。

RunConsoleAsync(IHostBuilder, CancellationToken)

启用控制台支持、生成和启动主机,并等待 Ctrl+C 或 SIGTERM 关闭。

UseConsoleLifetime(IHostBuilder)

侦听 Ctrl+C 或 SIGTERM 并调用 StopApplication() 来启动关闭进程。 这将解除阻止 RunAsync 和 WaitForShutdownAsync 等扩展。

UseConsoleLifetime(IHostBuilder, Action<ConsoleLifetimeOptions>)

侦听 Ctrl+C 或 SIGTERM 并调用 StopApplication() 来启动关闭进程。 这将解除阻止 RunAsync 和 WaitForShutdownAsync 等扩展。

UseContentRoot(IHostBuilder, String)

指定要由主机使用的内容根目录。

UseDefaultServiceProvider(IHostBuilder, Action<ServiceProviderOptions>)

指定要 IServiceProvider 为默认的 。

UseDefaultServiceProvider(IHostBuilder, Action<HostBuilderContext,ServiceProviderOptions>)

指定要 IServiceProvider 为默认的 。

UseEnvironment(IHostBuilder, String)

指定主机要使用的环境。

UseSystemd(IHostBuilder)

将主机生存期设置为 SystemdLifetime,为已启动和正在停止的应用程序提供通知消息,并将控制台日志记录配置为 systemd 格式。

UseWindowsService(IHostBuilder)

将主机生存期设置为 WindowsServiceLifetime,设置内容根,启用事件日志记录,并将应用程序名称作为默认源名称。

UseWindowsService(IHostBuilder, Action<WindowsServiceLifetimeOptions>)

程序初始化实用工具。

适用于