冠军

导航

各种各样的 Host Builder

各种各样的 Host Buider

If you're building for the web or writing a distributed application, you might need to use a different host builder. Consider the following list of additional host builders:

  • DistributedApplicationBuilder: A builder for creating distributed apps. For more information, see .NET Aspire.
  • WebApplicationBuilder: A builder for web applications and services. For more information, see ASP.NET Core.
  • WebHostBuilder: A builder for IWebHost. For more information, see ASP.NET Core web host.

见:https://learn.microsoft.com/en-us/dotnet/core/extensions/generic-host?tabs=appbuilder#additional-scenario-based-host-builders

HostApplicationBuilder

用来构建托管的应用和服务。从 .NET 6 开始提供。

见:https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.hostapplicationbuilder?view=net-8.0

WebApplicationBuilder

用于构建 Web 应用和 Web 服务的托管器,从 .NET 6 开始提供。现在推荐的方式。

见:https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.webapplicationbuilder?view=aspnetcore-8.0

DistributedApplicationBuilder

主要用于实现 .NET Aspire 中,用来管理分布式应用。它比较新,从 .NET 8 开始提供。

见: https://learn.microsoft.com/en-us/dotnet/api/aspire.hosting.distributedapplicationbuilder?view=dotnet-aspire-8.0

WebHostBuilder

最早在 .NET Core 就提供的用于开发 Web 应用的托管器,它从 .NET 1.0 就开始提供。

WebHostBuilder 提供了便利的方式来完成对 IServer he RequestDelegate 对象的封装。它提供了 UseHttpListenerServer() 方法用来注册 HttpListener。以及 Configure() 方法用来配置 Web 服务器注册处理中间件。

见:https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.webhostbuilder?view=aspnetcore-8.0

posted on 2024-10-28 09:31  冠军  阅读(32)  评论(0编辑  收藏  举报