The Visual Studio template for creating an ASP.NET Core project, since version 3.x, adds the following (or very similar) contents to the Program class:
publicstaticvoid Main(string[] args) { CreateHostBuilder(args).Build().Run(); } publicstatic IHostBuilder CreateHostBuilder(string[] args) => Host
.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(builder =>
{
builder.UseStartup<Startup>();
});
This has changed a bit since previous versions and is now more opinionated; I already showed this when talking about OWIN earlier in this chapter.
The Host class exposes the static CreateDefaultBuilder, which returns a fully built IHostBuilder instance. The CreateDefaultBuilder method is actually doing a lot of things behind our backs:
- Creates a ConfigurationBuilder and adds the environment variables provider to it (see Chapter 2, Configuration...