title: How to fix the Dependency Injection error in Startup.cs class in .NET Core
body: <p>I use ASP.NET Core 2.2
  I am trying to call a basic service class from Startup. It is throwing this exception:</p>
  
  <blockquote>
    <p>InvalidOperationException: Unable to resolve service for type
    'TIR.NetCore.ICommonLogService' while attempting to activate
    'AdminCentral.NetCore.Startup'.</p>
  </blockquote>
  
  <p>This my code:</p>
  
  <pre><code>public class Startup
  {
      private readonly ICommonLogService _CommonLogService;
      public Startup(IConfiguration configuration, ICommonLogService CommonLogService)
      {
           _CommonLogService = CommonLogService;
           Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
      public string connectionString;
  
      public IServiceProvider ConfigureServices(IServiceCollection services)
      {
          var container = new Container();
          container.Configure(config =&gt;
          {
              config.AddRegistry(new StructuremapRegistry());
              config.Populate(services);
          });
  
          return container.GetInstance&lt;IServiceProvider&gt;();
      }
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
        LogException(Exception )
     }
  
      private void LogException(Exception error, HttpContext context)
      {
           _CommonLogService.InsertLogDetail();
    }
  }
  </code></pre>