I am building a console .NET Core application. It periodically runs a method that does some work. How do I make ServiceProvider behave in the same way it behaves in ASP.NET Core apps. I want it to resolve scoped services when the method begins it's execution and dispose the resolved services at the end of the method.
// pseudocode
globalProvider.AddScoped<ExampleService>();
// ...
using (var scopedProvider = globalProvider.CreateChildScope())
{
var exampleService = scopedProvider.Resolve<ExampleService>();
}