Dynamically Change the ServiceLifetime of a Registered Service in .NET
The article shows how to replace a registration in IServiceCollection with another one with a different ServiceLifetime, using Replace and extension methods to swap implementation and environment.