title: How to setup app settings in a .Net Core 3 Worker Service
body: <p>I have been looking at a number of tutorials and SO questions (such as <a href="https://stackoverflow.com/questions/48778144/app-settings-net-core">App Settings .Net Core</a>) regarding reading appsettings.json in .Net Core 3 and I cannot find any pointers on how-to when dealing with the Worker service. There is no Startup method. Instead, I have a Program.cs with the main method:</p>
  
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          CreateHostBuilder(args).Build().Run();
      }
  
      public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureServices((hostContext, services) =&gt;
              {
                  services.AddHostedService&lt;Worker&gt;();
              });
  }
  </code></pre>
  
  <p>How do I go about reading from the appsettings.json file in a Worker Service Project in .Net Core 3?</p>
  
  <p>I have added a reference to a custom WCF client I created with .Net v4.8 and another project that has just all the Busines Domain Object shared between the whole solution. My solution is primarily .Net v4.8 and I want to use the Worker Service. The Client project creates a WCF Client internally by code so all binding and endpoints are configurable. If this were a .Net v4.8 project, I'd add the following to the app.config:</p>
  
  <pre><code>&lt;appSettings&gt;
      ...
      &lt;add key="AminServiceUri" value="http://localhost:45108/ServiceHost/v1/AminService.svc" /&gt;
      &lt;add key="BillServiceUri" value="http://localhost:45108/ServiceHost/v1/BillService.svc" /&gt;
      &lt;add key="CustomerServiceUri" value="http://localhost:45108/ServiceHost/v1/CustomerService.svc" /&gt;
      &lt;add key="EpayServiceUri" value="http://localhost:45108/ServiceHost/v1/EpayService.svc" /&gt;
      &lt;add key="FinanceServiceUri" value="http://localhost:45108/ServiceHost/v1/FinanceService.svc" /&gt;
      &lt;add key="GrpServiceUri" value="http://localhost:45108/ServiceHost/v1/GrpService.svc" /&gt;
      &lt;add key="MetaServiceUri" value="http://localhost:45108/ServiceHost/v1/MetaService.svc" /&gt;
      &lt;add key="ReportServiceUri" value="http://localhost:45108/ServiceHost/v1/ReportService.svc" /&gt;
      &lt;add key="ServiceInfoServiceUri" value="http://localhost:45108/ServiceHost/v1/ServiceInfoService.svc" /&gt;
      &lt;add key="UsersServiceUri" value="http://localhost:45108/ServiceHost/v1/UsersService.svc" /&gt;
      ...
      &lt;add key="ExcessiveLogging" value="false" /&gt;
      ...
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>Now I need these settings to be in the new JSON format and read them in.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is a fresh project. The worker is not doing anything:</p>
  
  <pre><code>public class Worker : BackgroundService
  {
      private readonly ILogger&lt;Worker&gt; logger;
  
      public Worker(ILogger&lt;Worker&gt; logger)
      {
          this.logger = logger;
      }
  
      protected override async Task ExecuteAsync(CancellationToken stoppingToken)
      {
          while (!stoppingToken.IsCancellationRequested)
          {
              logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
              await Task.Delay(5000, stoppingToken);
          }
      }
  }
  </code></pre>
  
  <p>And here is how I get this project type:</p>
  
  <p><a href="https://i.stack.imgur.com/TFQAN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/TFQAN.png" alt="Worker Service"></a></p>