title: How to solve Dependency injection and Inconsistent accessibility parameter type '' in .Net 3 Worker service?
body: <p>I am setting a .Net core worker services that will get some data from the database and pass that to an endpoints. So I am trying to set it up base on my .net MVC knowledge. While setting up, I got this error:</p>
  <blockquote>
  <p>Unhandled exception. System.ArgumentNullException: Value cannot be
  null. (Parameter 'implementationInstance')    at
  Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton[TService](IServiceCollection
  services, TService implementationInstance</p>
  </blockquote>
  <p>I created a class where the logic for fetch data from a stored procedure. This is the Business call:</p>
  <pre class="lang-cs prettyprint-override"><code>namespace AgencyBankingSettlement.Business
  {
      public class ServiceTask
      {
          private readonly AgencyBankingSettlementDbContext context;
  
          public ServiceTask(AgencyBankingSettlementDbContext _context)
          {
              context = _context;
          }
          public IEnumerable&lt;Testing&gt; Request() {
              var person = context.Testings.FromSqlRaw&lt;Testing&gt;(&quot;dbo.spPerson_GetAll&quot;);
              return person;
          }
      }
  }
  </code></pre>
  <p>This is my program.cs. In the program.cs file I set up dependency injection so that I can easily inject into my classes and you it:</p>
  <pre class="lang-cs prettyprint-override"><code>public static void Main(string[] args)
  {
      CreateHostBuilder(args).Build().Run();
  }
  
  public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
      Host.CreateDefaultBuilder(args)
          .ConfigureServices((hostContext, services) =&gt;
          {
              IConfiguration configuration = hostContext.Configuration;
  
              AppSettings appSettings = configuration.GetSection(&quot;ContextCore&quot;).Get&lt;AppSettings&gt;();
  
              services.AddSingleton(appSettings);
              services.AddScoped&lt;ServiceTask&gt;();
  
              services.AddDbContext&lt;AgencyBankingSettlementDbContext&gt;(options =&gt;
              options.UseSqlServer(hostContext.Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
  
              services.AddHostedService&lt;Worker&gt;();
          });
  </code></pre>
  <p>So in my worker.cs. I want to be able to access the ServiceTask file and log the &quot;persons&quot; information that will be injected from the serviceTask. I could not also access the file. If I can fix this then every other thing I want to do will also follow the same pattern.</p>
  <pre class="lang-cs prettyprint-override"><code>public class Worker : BackgroundService
  {
      private readonly ServiceTask serviceTask;
      private readonly ILogger&lt;Worker&gt; _logger;
      
  
      public Worker(ILogger&lt;Worker&gt; logger, ServiceTask _serviceTask)
      {
          serviceTask = _serviceTask;
          _logger = logger;
          
      }
  
      protected override async Task ExecuteAsync(CancellationToken stoppingToken)
      {
          while (!stoppingToken.IsCancellationRequested)
          {
              var persons = serviceTask.Request();
                  _logger.LogInformation(persons);
              _logger.LogInformation(&quot;Worker running at: {time}&quot;, DateTimeOffset.Now);
              await Task.Delay(1000, stoppingToken);
          }
      }
  }
  </code></pre>
  <p>How can I make this to work?</p>