You can register you Dbcontext in Unity with HierarchicalLifetimeManager, create new child container and resolve Entity Manager from new child container. So, you will have new instance of Dbcontext for every Entity Manager.
Resolving complex object graph with Unity
-
06-10-2022 - |
문제
I have the following situation, arrows represent dependencies:
How can I resolve an Entity Manager object? When I resolve one, it creates 2 instances of the customer and address repository, but these instances need the same Dbcontext!
But I do not want the Dbcontext to be static in the entire application, when resolving another entity manager, it should resolve a separate dbcontext...
해결책
다른 팁
Maybe PerResolveLifetimeManager
for DBContext
could help you.
All objects in graph has the same instance but a new instance is created in every graph resolve.
Full example here.
제휴하지 않습니다 StackOverflow