I have an ASP .Net 6 Web API. In it, I have a Singleton service which requires the use of a Transient service. So I inject IServiceProvider into the Singleton service, and then get an instance of the Transient service as follows:
using (var serviceScope = _serviceProvider.CreateScope())
{
using (var service = (MyTransientService)serviceScope.ServiceProvider.GetRequiredService<IMyTransientService>())
{
// Use transient service
}
}
Now, I'd like to add some constructor arguments to my Transient service. How would I be able to provide these parameters when getting the service (as in the code above)?
I've searched the internet, but all examples I found show how to pass parameters when registering the service in Startup.cs (in the ConfigureServices() method), when knowing the values of the parameters upfront.
Any pointers would be greatly appreciated. Thanks.