I'm trying to get the Repository/UnitOfWork pattern figured out. We're working on a project with EntityFramework and our DBContext contains 200+ tables.

Right now our approach is to inject whatever repository is required to a service. This way the services can only call a few methods from the passed repository. Services are easy to test because it's easy to fake the injected repositories.

  • When using a UnitOfWork pattern, should the UnitOfWork contain every single Repository from the project?
  • Would it be ok to have multiple, different UnitOfWorks (containing different Repositories) for different parts of an application?
  • 1
    The Unit of Work should only reference the repositories that it needs. – Robert Harvey Oct 24 '18 at 17:16
  • And it would be ok to have many different UnitsOfWork for every case you need. – Fabio Oct 25 '18 at 5:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.