Open Naun opened 3 years ago
@Naun AddScoped registers the service with container lifetime. If you want the child container to have its own instance, then register the service in the child container, not the root, or make sure the service is registered in unity container with hierarchical lifetime
Hi Amleto,
Thank you for your answer. But, that does not explain:
serviceCollection.AddScoped<DbContext>();
instead of using the lambda expression, the unit test passes: it provides two different instances of DbContext... Why?
Hi,
I need your help to understand if the following behavior is the expected one or if there is a trick to make it work. It seems that when there are nested dependency injections, the scope registrations are not taken into account. To make it clearer, I was expecting this test to pass, but it does not. It is failing to the last assertion:
My question is: does unity container creates a new scope when creating a child container?
Full test class: NestedInjectionTests.log