title: Why we need to call BuildServiceProvider to get dependencies everytime?
body: <p>After registering instances on my <code>IServiceCollection</code>, I need to register an <code>IAutomapperProvider</code> that depends on an <code>IAssemblyProvider</code> that was registered before this method call</p>
  
  <pre><code>public static IServiceCollection RegisterAutomapperConfiguration(this IServiceCollection container, ServiceLifetime lifeTime = ServiceLifetime.Scoped)
  {
          //creating the provider to get the IAssemblyProvider for my IAutomapperProvider
          var prov = container.BuildServiceProvider();
          var assemblyProvider = prov.GetService&lt;IAssemblyProvider&gt;();
          container.Register&lt;IAutomapperProvider&gt;(aProv =&gt; new AutomapperProvider(assemblyProvider), lifeTime);
          var autoMapperProvider = prov.GetService&lt;IAutomapperProvider&gt;();
          var mapperConfig = autoMapperProvider.GetMapperConfiguration();
          ...
  }
  </code></pre>
  
  <p>If right after the call of <code>container.Register&lt;IAutomapperProvider&gt;(aProv =&gt; new AutomapperProvider(assemblyProvider), lifeTime);</code>
   I don't call BuildServiceProvider again, then I would not get the IAutomapperProvider I registered before</p>
  
  <pre><code>public static IServiceCollection RegisterAutomapperConfiguration(this IServiceCollection container, ServiceLifetime lifeTime = ServiceLifetime.Scoped)
  {
          //creating the provider to get the IAssemblyProvider for my IAutomapperProvider
          var prov = container.BuildServiceProvider();
          var assemblyProvider = prov.GetService&lt;IAssemblyProvider&gt;();
          container.Register&lt;IAutomapperProvider&gt;(aProv =&gt; new AutomapperProvider(assemblyProvider), lifeTime);
          prov = container.BuildServiceProvider();
          var autoMapperProvider = prov.GetService&lt;IAutomapperProvider&gt;();
          var mapperConfig = autoMapperProvider.GetMapperConfiguration();
          ...
  }
  </code></pre>
  
  <p>On the AspNetCore code when you call BuildServiceProvider extension method they use the same IServiceCollection that can change over the time adding more elements, at the end you are pointing to the same reference</p>
  
  <pre><code>public static ServiceProvider BuildServiceProvider(this IServiceCollection services)
  {
      return BuildServiceProvider(services, ServiceProviderOptions.Default);
  }
  </code></pre>
  
  <p>Then why I need to call it again to get a new instance that knows how to resolve my Service?</p>
  
  <p>To avoid confusions, the Register method is an extension I created but internally calls the AddSinglenton or Add...</p>
  
  <pre><code>  public static IServiceCollection Register&lt;TService&gt;(this IServiceCollection container, Func&lt;IServiceProvider, TService&gt; implementationFactory, ServiceLifetime lifeTime)
          where TService : class
      {
  
      if (container == null)
          throw new ArgumentNullException(nameof(container));
      if (implementationFactory == null)
          throw new ArgumentNullException(nameof(implementationFactory));
  
      switch (lifeTime)
      {
          case ServiceLifetime.Scoped:
              container.AddScoped(typeof(TService), (Func&lt;IServiceProvider, object&gt;)implementationFactory);
              break;
          case ServiceLifetime.Transient:
              container.AddTransient(typeof(TService), (Func&lt;IServiceProvider, object&gt;)implementationFactory);
              break;
          default:// ServiceLifetime.Singleton
              container.AddSingleton(typeof(TService), (Func&lt;IServiceProvider, object&gt;)implementationFactory);
              break;
      }
  
      return container;
  }
  </code></pre>