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