Should Service Depend on Many Repositories, or Break Them Up?

Posted by Josh Pollard on Stack Overflow See other posts from Stack Overflow or by Josh Pollard
Published on 2010-02-12T03:40:55Z Indexed on 2010/03/12 22:07 UTC
Read the original article Hit count: 123

I'm using a repository pattern for my data access. So I basically have a repository per table/class. My UI currently uses service classes to actually get things done, and these service classes wrap, and therefore depend on repositories. In many cases my services are only dependent upon one or two repositories, so things aren't too crazy. Unfortunately, one of my forms in the UI expects the user to enter data that will span five different tables. For this form I made a single service class that depends upon five repositories. Then the methods within the service for saving and loading the data call the appropriate methods on all of the corresponding repositories.

As you can imagine, the save and load methods in this service are really big. Also, unit testing this service is getting really difficult because I have to setup so many fake repositories.

Would it have been a better choice to break this single service apart into a few smaller services? It would put more code at the UI layer, but would make the services smaller and more testable.

© Stack Overflow or respective owner

Related posts about repository-pattern

Related posts about service