title: How to get and inject the IHostApplicationLifetime in my service to the container (Console App)
body: <p>Following this <a href="https://stackoverflow.com/a/55960329/375460">answer</a>, I want to inject the <code>IHostApplicationLifetime</code> in my class to shutdown properly when the method <code>StartAsync</code> is over.</p>
  
  <p>But I don't know how to get the applicationLifetime from the console and Inject it through de built-in dotnet core IoC container:</p>
  
  <pre><code>public static IHostBuilder CreateHostBuilder(string[] args)
  {
      return Host.CreateDefaultBuilder(args)
          .ConfigureAppConfiguration((hostingContext, config) =&gt;
          {
              config.SetBasePath(Directory.GetCurrentDirectory())
              .AddCommandLine(args)
              .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
          })
          .ConfigureServices((hostContext, services) =&gt;
          {
              services.Configure&lt;ConnectionStringConfiguration&gt;(hostContext.Configuration.GetSection("ConnectionStrings"));
              services.AddTransient&lt;ISmtpClient, MySmtpClient&gt;();
              services.AddTransient&lt;IEmailService, EmailService&gt;();
              services.AddSingleton&lt;IHostApplicationLifetime&gt;(????); // What should I put here ????
              services.AddHostedService&lt;EInvoiceSenderService&gt;();
          })
          .UseSerilog();
  }
  </code></pre>
  
  <p>Thank you !</p>