I have an ASP.NET Core 2.2 application and I'd like to configure a service to be "singleton" for a request. Using InstancePerLifetimeScope works as long as you don't create child scopes. There are some processes which are running in child scopes, created from the scope of the request.
Using InstancePerRequest doesn't work in ASP.NET Core 2.2 (this is basically what I need).
Did anyone encounter this situation and found a solution?
using(var scope1 = container.BeginLifetimeScope())
{
var w1 = scope1.Resolve<Worker>(); // should resolve worker 1
using(scope2 = scope1.BeginLifetimeScope())
{
var w2 = scope2.Resolve<Worker>(); // should resolve same worker as w1
}
}
using(scope3 = container.BeginLifetimeScope())
{
var w3 = scope3.Resolve<Worker>(); // should resolve another worker
}