سؤال

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