title: Exception thrown: 'System.InvalidOperationException' in Microsoft.Extensions.DependencyInjection
body: <p>I am doing the webjobs using ASP.NET Core. I'm not able to set the dependency injection properly.</p>
  <pre><code>public static async Task Main(string[] args)
      {
              var host = BuildHost(args);
  
              using (host)
              {
                  await host.RunAsync();
              }
      }
  
  
      public static IHost BuildHost(string[] args) =&gt;
  new HostBuilder()
      .ConfigureHostConfiguration(builder =&gt; 
      {
          builder
              .SetBasePath(Directory.GetCurrentDirectory())
              .AddJsonFile(&quot;appsettings.json&quot;)
              .AddEnvironmentVariables();
      })
      .ConfigureWebJobs(b =&gt;
      {
          b.AddAzureStorageCoreServices();
          b.AddAzureStorage();
          b.AddTimers();
      })
      .ConfigureServices((hostBuilderContext, services) =&gt;
      {
          services.AddScoped&lt;ISchedularService, SchedularService&gt;();
          //services.AddSingleton&lt;IHostedService, PrintTimeService&gt;()
      }).Build();
  </code></pre>
  <p>And in the functions.cs file, I have accessed the scheduler service in the constructor. but it didn't fire the constructor and throws an exception like:</p>
  <blockquote>
  <p>Exception thrown: 'System.InvalidOperationException' in Microsoft.Extensions.DependencyInjection</p>
  </blockquote>
  <pre><code>public class Functions
  {
  
      private readonly ISchedularService _schedularService;
      public Functions(SchedularService schedularService)
      {
          _schedularService = schedularService;
      }
  }
  </code></pre>