views:

250

answers:

2

So I have a repository for basically each entity but my model has a relational division where entities aren't directly related in the model. So what I need to do is query off of that indirect relationship and return a collection of entities. Is it appropriate to initialize and invoke queries on a different repository from the one you are actually querying against? If not, whats the best solution to this - a helper class?

Thanks

+2  A: 

A Repository for every entity is probably not a good idea. Repositories should exist for aggregate root objects. Define your aggregate root objects and provider Repositories for those. That may clear up some of the mess when it comes to repositories taking dependencies on other repositories.

Chris Holmes
+6  A: 

I agree - try to identify Aggregate roots. If you are not familiar with aggreagate roots: read here

Your original question is still valid in my opinion though, you might still have dependencies to other repositories. It could be ok to have theese dependencies, depending on your domain model. If you have dependencies like this it is a good design to loosely couple them with interfaces. You can then use some kind of dependency injection to allow for easier testing etc. Another option is to have a factory give you the right repository.

Jon