Question

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

Était-ce utile?

La solution

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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top