Back to results for “Generic Host”
.NET › Generic Host

What is the difference between Host.CreateApplicationBuilder and the older Host.CreateDefaultBuilder?

Intermediate

Answer

Host.CreateApplicationBuilder (introduced in .NET 7) is the modern, minimal-hosting-model-aligned builder returning a HostApplicationBuilder with more direct, immediate access to Services, Configuration, and Logging properties for a more streamlined top-level-statements-friendly syntax. Host.CreateDefaultBuilder (the older pattern, still supported) uses the more verbose builder-pattern-with-callbacks style (ConfigureServices, ConfigureAppConfiguration lambdas) common in .NET Core 2.x-6.x style Program.cs/Startup.cs files.
// Modern (.NET 7+)
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();

// Older style, still supported
var host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((context, services) => {
        services.AddHostedService<Worker>();
    })
    .Build();
Real-world example A team modernizing an older Worker Service project migrates from the callback-heavy CreateDefaultBuilder pattern to CreateApplicationBuilder, reducing boilerplate and aligning with the same minimal hosting style used in their newer ASP.NET Core projects.

Common follow-ups: Are there any capabilities CreateDefaultBuilder has that CreateApplicationBuilder lacks?;How does this migration affect existing ConfigureServices callback code?