Включено ли UseConsoleLifetime по умолчанию в универсальный хост .NET (Host.CreateDefaultBuilder)?C#

Место общения программистов C#
Ответить
Anonymous
 Включено ли UseConsoleLifetime по умолчанию в универсальный хост .NET (Host.CreateDefaultBuilder)?

Сообщение Anonymous »


I initially configured my Console application using .NET generic host as follows:

var builder = new HostBuilder() .ConfigureServices((hostContext, services) => { services.AddLogging(); }) .ConfigureLogging((hostContext, configLogging) => { configLogging.AddConsole(); }) .UseConsoleLifetime() .Build(); await builder.RunAsync(); Then I realized I also needed appsettings.json and appsettings.{Environment}.json, which led me to the decision to use Host.CreateDefaultBuilder, as it includes the default logging, appsettings, and some other defaults:

var host = Host.CreateDefaultBuilder(args) .ConfigureServices(services => { }) .UseConsoleLifetime() // Is this line necessary? .Build(); Now I wonder if UseConsoleLifetime is actually included in the default builder. I wasn't able to find it by decompiling several source code files, but just to be sure, I decided to ask this question.

Here is the Microsoft docs:

Источник: https://stackoverflow.com/questions/780 ... reatedefau
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»