title: Dependency injection of type having nested dependency
body: <p>I want to create a type which contains another dependency.</p>
  
  <p>The reason is so that I can make the controller rely on a Infrastructure wrapper with more abstracted functions which then actually access the data layer.</p>
  
  <p>So here is the wrapper having dependency of dbcontext</p>
  
  <pre><code>public Repository(IdbContext context)
  {
      _context = context;
  }
  </code></pre>
  
  <p>The controller constructor:</p>
  
  <pre><code>private readonly Repository _repo;
  
  public TheController(IRepository repo)
  {
      _repo = repo;
  }
  </code></pre>
  
  <p>In the <em>Startup.cs</em>, <code>ConfigureServices</code>:</p>
  
  <pre><code>services.AddDbContext&lt;dbContext&gt;(options =&gt;         
      options.UseSqlServer(Configuration.GetConnectionString("dbContext")));
  services.AddTransient&lt;IRepository, Repository&gt;();
  </code></pre>
  
  <p>In the <em>Program.cs</em>, </p>
  
  <pre><code>using (var scope = host.Services.CreateScope())
  {
      var services = scope.ServiceProvider;
      var context = services.GetRequiredService&lt;dbContext&gt;();
      var _repo = services.GetRequiredService&lt;IRepository&gt;();
      ...
  }
  </code></pre>
  
  <p>The <code>GetRequiredService&lt;IRepository&gt;()</code> fails with following Exception:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: 'Unable to resolve service for type 
          'namespace.Models.IdbContext' while attempting to activate 
          'namespace.Repositories.Repository'.'</p>
  </blockquote>