.NET Web host (Web Host)

       ASP.NET Core application configuration and launch a host. The host is responsible for app launch and lifecycle management. In the minimum case, the configuration of a host and a service request processing pipeline. In addition, the host can also create a log, dependency injection, configuration.

       This article contains a Web host, which is still available, but only as a backwards compatible use. For all types of app, we recommend using the Generic Host .

 The establishment of a host

        Use IWebHostBuilder one example of a web to create a host. Typically, the host will be performed to establish a web app entry point in the Main function.

        In the project template, Main function is included in Program.cs in a typical app will call CreateDefaultBuilder to start building a web host:

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

        Call the CreateDefaultBuildercode for the method is called CreateWebHostBuilderthe method, which will be separated from the Main function code in the Main function, we call the Run method on the builder object. If you use Entity Framework Core tools this tool, then, that such separation is necessary, this tool expects to find a CreateWebHostBuilderway so that they can be called at design time to configure the host, without running the app. Another alternative is to use IDesignTimeDbContextFactory. For more information, please refer to the Design-Time DbContext Creation .

Guess you like

Origin www.cnblogs.com/qianxingmu/p/12441547.html