title: Calling 'BuildServiceProvider' from application code results in copy of Singleton warning. How do I avoid this?
body: <p>I just pasted the 4 lines at the end from another project and it works but I get a warning.. I clearly do not understand DI well enough ... What does it want me to change ? </p>
  
  <pre><code>  public void ConfigureServices(IServiceCollection services)
          {
              if (HostingEnvironment.EnvironmentName == "Local")
              {
                  services.AddHealthChecksUI()
                 .AddHealthChecks()
                 .AddCheck&lt;TestWebApiControllerHealthCheck&gt;("HomePageHealthCheck")
                 .AddCheck&lt;DatabaseHealthCheck&gt;("DatabaseHealthCheck");
              }
  
          services.Configure&lt;PwdrsSettings&gt;(Configuration.GetSection("MySettings"));
          services.AddDbContext&lt;PwdrsContext&gt;(o =&gt; o.UseSqlServer(Configuration.GetConnectionString("PwdrsConnectionRoot")));
  
          services.AddMvc(o =&gt;
          {
              o.Filters.Add&lt;CustomExceptionFilter&gt;();
          });
  
          services.AddCors(options =&gt;
          {
              options.AddPolicy("CorsPolicy", b =&gt; b
                  .SetIsOriginAllowed((host) =&gt; true)
                  .AllowAnyMethod()
                  .AllowAnyHeader()
                  .AllowCredentials());
          });
  
          services.AddSwaggerDocument();
          services.AddHttpContextAccessor();
  
          services.AddAutoMapper(typeof(ObjectMapperProfile));
          services.AddTransient&lt;IEmailSender, EmailSender&gt;();
          services.AddScoped(typeof(IAppLogger&lt;&gt;), typeof(LoggerAdapter&lt;&gt;));
          services.AddScoped(typeof(IAsyncRepository&lt;&gt;), typeof(Repository&lt;&gt;));
          services.AddScoped&lt;IRfReportTypeRepository, RfReportTypeRepository&gt;();
          services.AddScoped&lt;IRfReportRepository, RfReportRepository&gt;();
          services.AddScoped&lt;IRfReportLookupsService, RfReportLookupsService&gt;();
          services.AddScoped&lt;IRfReportService, RfReportService&gt;();
  
          services.Configure&lt;RAFLogging&gt;(Configuration.GetSection("RAFLogging"));
          ServiceProvider serviceProvider = services.BuildServiceProvider(); //WARNING IS HERE
          IOptions&lt;RAFLogging&gt; RAFLogger = serviceProvider.GetRequiredService&lt;IOptions&lt;RAFLogging&gt;&gt;();
          RegisterSerilogLogger logger = new RegisterSerilogLogger(RAFLogger);
      }
  </code></pre>