title: How does the Func delegate work when it requires an interface as a parameter?
body: <p>Specifically, I'm looking at this line of code from Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.cs:</p>
  <pre><code>public static IServiceCollection AddScoped&lt;TService&gt;(this IServiceCollection services, Func&lt;IServiceProvider, TService&gt; implementationFactory) where TService : class;
  </code></pre>
  <p>An example using this method would be:</p>
  <pre><code>services.AddScoped&lt;ICustomService&gt;(sp =&gt; new CustomService(
      sp.GetRequiredService&lt;IAnotherCustomService&gt;(), &quot;Param1&quot;, &quot;Param2&quot;));
  </code></pre>
  <p>I understand how the Func delegate and lambda expressions work, but I'm not understanding how <code>IServiceProvider</code> is being initialized behind the scenes.</p>