✅ Difference between CreateApplicationBuilder and CreateDefaultBuilder?
Only difference I can see is that CreateApplicationBuilder returns a HostApplicationBuilder and CreateDefaultBuilder returns a HostBuilder?
5 Replies
Like don't these code blocks do the same thing?
CreateDefaultBuilder()
literally just creates a host builder with an empty ServiceCollection
. It also doesn't have any properties for anything on the host, so you have to configure everything via the .ConfigureXxx()
methods. At this point, it's basically a legacy type.
CreateApplicationBuilder
creates a host builder that's used for top-level statements to start an application. There are properties from which to access various application elements (Services, Configuration, etc.), and some stuff is already pre-configured (using environment variables and appsettings.json for configuration; a default logger to the console; and which environment the app is running in; etc.I see, so is there any reason to use
CreateDefaultBuilder()
over CreateApplicationBuilder()
?none, really
Guessing that's why worker template uses
CreateApplicationBuilder()
now? since from what I've seen, in the past worker template used to use CreateDefaultBuilder()
Thanks for the explanation