If called BuildServiceProvider() in ConfigureServices, shown warning “Calling ‘BuildServiceProvider’ from application code results in a additional copy of Singleton services being created”
Calling BuildServiceProvider creates a second container, which can create torn singletons and cause references to object graphs across multiple containers.
ASP.NET Core will build the ServiceProvider automatically at runtime, therefore don’t call the BuildServiceProvider() manually.
I read Adam Freeman’s Pro ASP.NET Core 3 8th book. Adam Freeman used app.ApplicationServices instead of services.BuildServiceProvider() in page 157 for this purpose, that app is Configure method’s parameter that this method located in Startup.cs
I thinks correct version is to use ApplicationServices property of app, which app is IApplicationBuilder in Configure method’s parameter. ApplicationServices’s type is IServiceProvider.

Adam Freeman’s Pro ASP.NET Core 3 8th book : Pro ASP.NET Core 3
Adam Freeman’s example project: SportStore project’s Startup.cs, SportStore project’s SeedData.cs
Microsoft’s recommendations about DI : Dependency injection in ASP.NET Core
Similar questions’ answers in Stackoverflow: https://stackoverflow.com/a/56058498/8810311, https://stackoverflow.com/a/56278027/8810311