Entity Framework using Repository Pattern, Unit of Work and Unity

entity-framework inversion-of-control repository-pattern unit-of-work unity-container

Accepted Answer

What you need, in my opinion, is a per-request lifetime manager that limits the number of UnitOfWork instances and DbContext instances you can have active at any given time. You may achieve this using the ASP.NET MVC bootstrapper for Unity in Unity 3 that has a PerRequestLifetimeManager.

You could potentially use a PerResolveLifetimeManager if you are not using ASP.NET. A HierarchicalLifetimeManager paired with a child container is another strategy I've seen (which makes the registrations a singleton within the child container).

8
10/1/2013 2:47:57 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow