문제

I have the following situation, arrows represent dependencies:

Hierarchy

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...

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top