I think I'm going in circles.
I'm working on an MVC 3 solution using EF4 & POCOs (database-first) and IoC. My repository and UoW patterns were mostly adopted from this article and this article.
My solution is made up of the following projects:
Implementations:
- Presentation (MVC site)
- Domain Services (business layer)
- Domain Repository (data access)
- Domain Context (my EF4 edmx and generated context)
- Domain Models (my EF4 generated POCOs)
Interfaces:
- Domain Services Interfaces (business layer interfaces)
- Domain Repository Interfaces (data access interfaces)
- Domain Context Interfaces (interfaces for generated EF4 context)
And lastly, the IoC project that ties everything together.
If you notice in that first article, the author mentions removing the dependency on ObjectSet from the domain services. This, I'm assuming, is for testability. Problem with this, though, is that it hinders the ability to do complex queries from the domain services, because IObjectSet and IEnumerable (returned by most methods on repository) don't stub out methods for complex querying.
Does this imply that I should be doing my complex querying in my repository? Should I move away from methods like public T Single(Expression<Func<T, bool>> where)
and stick to methods like public T GetUserById(int id)
?
If this is not the case, then how do I do complex queries such as this in my service layer?
Looking at my solution outline above and the questions I have, am I moving in the right direction, or am I creating problems for myself?
Thanks in advance.
IQueryable
is the key here. – Steven