January 9, 2021
This is the entry-point of our application. An ASP.NET application is started in the same way as a console application, from a static void Main() function. 

This is where we configure the web host that will serve the requests. The host is responsible for app startup and lifetime management, including graceful shutdown. At a minimum, the host configures a server and a request processing pipeline. The host can also set up logging, dependency injection, and configuration.
public class Program
    public static void Main(string[] args)

    public static IHostBuilder CreateHostBuilder(string[] args) =>
            .ConfigureWebHostDefaults(webBuilder =>
The CreateDefaultBuilder method loads the configuration from the environment variables and the apppsettings files. It also configures the logging mechanism that your app will use. Once the host is configured, the call to Build() creates the actual IHost instance. But the application still not handling any HTTP requests, yet. It's the call to Run() method that starts the HTTP server.

At this point, your app is ready to handle requests from a client.

You might be tempted to refactor the above code and move the CreateHostBuilder() method inside Main(). However, if the app uses Entity Framework Core, don't change the name or signature of the CreateHostBuilder() method. The Entity Framework Core tools expect to find a CreateHostBuilder method that configures the host without running the app. For more details, see the documentation and this StackOverflow question.