Working with .NET Generic Host instead of WebHostBuilder

Prior to ASP.NET Core 2.1, the Main method defined a host as WebHostBuilder as follows:

public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseStartup<Startup>()
                .Build();
            host.Run();
        }

This meant that every application was tied to be hosted as a web application. ASP.NET Core 2.1 introduced the generic host, which allows for applications that do not necessarily have to process web-based HTTP requests.

There are other applications, such as messaging and background applications, where it doesn't make sense to be tied to WebHostBuilder abstraction as before and, therefore, a more generic HostBuilder program initialization abstraction was introduced. An example of this in its raw form is shown as follows:

public static Task Main(string[] args) 
{
var host = new HostBuilder()
.Build();
host.Run();
}

Previous versions of ASP.NET had a CreateWebHostBuilder() method in the Main method, which is being replaced by the CreateHostBuilder() method in ASP.NET Core 3, and, instead of using a WebHost.CreateDefaultBuilder(args) method, we now have Host.CreateDefaultBuilder(args).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.19.75