title: assert that a service has been injected as scoped service
body: <p>I am writing a unit test for the following extension method:</p>
  <pre class="lang-cs prettyprint-override"><code>public static void AddMyServices(this IServiceCollection services)
  {
      services.AddScoped&lt;IServiceA, ServiceA&gt;();
  }
  </code></pre>
  <p>Here is what I have to confirm the <code>ServiceA</code> has been injected.</p>
  <pre class="lang-cs prettyprint-override"><code>[Test]
  public void Should_Resolve_ServiceA() {
      // Arrange
      var services = new ServiceCollection();
  
      // Act
      services.AddMyServices();
      var serviceProvider = services.BuildServiceProvider();
      var actual = serviceProvider.GetService&lt;IServiceA&gt;();
  
      // Assert
      Assert.IsNotNull(actual);        
  }
          
  </code></pre>
  <p>The test above did ensure the service has been injected. However, <code>services.AddSingleton</code> and <code>services.AddTransient</code> also pass the test.</p>
  <p>Is there a solution to get only the scoped injected services so I can ensure it has been injected the correct way?</p>
  <p><em>I am aware that for the simplified example above, I can create a stub for <code>IServiceCollection</code> and check the <code>ReceivedCalls</code> on the stub method. However, I am trying to avoid doing that because I have a lot of <code>AddScope</code> statements in my real extension method and part of the purpose of the unit test above is to ensure all dependencies of a specific service have been injected. So <code>GetService&lt;T&gt;</code> is the preferred way to do the testing.</em></p>