ConfigureWebHostDefaults adds web-host defaults to an IHostBuilder. It configures the WebHostBuilder, including Kestrel, so an ASP.NET Core application can listen for HTTP requests. section 30.2
The method complements Host.CreateDefaultBuilder rather than replacing it. The generic host supplies shared features such as configuration, logging, and dependency injection; web-host defaults add the services needed for HTTP applications. section 30.2
Configure a Startup-based web host
CreateHostBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); The resulting host can be built and run with Build().Run(). Use Startup to register dependency-injection services and configure the middleware pipeline. section 30.2 section 30.7
Listing 30.1 The Program.cs file configures and runs an IHost
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args) #1
.Build() #2
.Run(); #3
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args) #4
.ConfigureWebHostDefaults(webBuilder => #5
{
webBuilder.UseStartup<Startup>(); #6
});
}
See the complete Program.cs flow from creating the host builder through building and running the IHost. section 30.2
