diff --git a/docs/core/extensions/generic-host.md b/docs/core/extensions/generic-host.md index 906a5e8021595..f9a040858984b 100644 --- a/docs/core/extensions/generic-host.md +++ b/docs/core/extensions/generic-host.md @@ -3,7 +3,7 @@ title: .NET Generic Host author: IEvangelist description: Learn about the .NET Generic Host, which is responsible for app startup and lifetime management. ms.author: dapine -ms.date: 05/22/2024 +ms.date: 09/11/2024 --- # .NET Generic Host @@ -196,11 +196,11 @@ Host configuration is used to configure properties of the [IHostEnvironment](#ih # [IHostApplicationBuilder](#tab/appbuilder) -The host configuration is available in property and the environment implementation is available in property. To configure the host, access the `Configuration` property and call any of the available extension methods. +The host configuration is available in property and the environment implementation is available in property. To configure the host, access the `Configuration` property and call any of the available extension methods. To add host configuration, consider the following example: -:::code language="csharp" source="snippets/configuration/console-host/Program.cs" highlight="6-9"::: +:::code language="csharp" source="snippets/configuration/console-host/Program.cs" highlight="6-8"::: The preceding code: diff --git a/docs/core/extensions/snippets/configuration/console-host/Program.cs b/docs/core/extensions/snippets/configuration/console-host/Program.cs index d02925c390a12..beeb282e6a6e8 100644 --- a/docs/core/extensions/snippets/configuration/console-host/Program.cs +++ b/docs/core/extensions/snippets/configuration/console-host/Program.cs @@ -1,12 +1,18 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); +HostApplicationBuilderSettings settings = new() +{ + Args = args, + Configuration = new ConfigurationManager(), + ContentRootPath = Directory.GetCurrentDirectory(), +}; -builder.Environment.ContentRootPath = Directory.GetCurrentDirectory(); -builder.Configuration.AddJsonFile("hostsettings.json", optional: true); -builder.Configuration.AddEnvironmentVariables(prefix: "PREFIX_"); -builder.Configuration.AddCommandLine(args); +settings.Configuration.AddJsonFile("hostsettings.json", optional: true); +settings.Configuration.AddEnvironmentVariables(prefix: "PREFIX_"); +settings.Configuration.AddCommandLine(args); + +HostApplicationBuilder builder = Host.CreateApplicationBuilder(settings); using IHost host = builder.Build();