Guys,
I've been reading both ddd and PoEAA books, and searching a lot on the web but i'm still confused and i think there is something i'm missing about the repository pattern:
Context of use: Web apps (monorail + activerecord)
What i'm looking for:
- reuse a 'base' repository among project. The repository will be the typical IRepository<T> with create, update, delete and query support.
- use decorator chains to support logging, etc.
- Have a consistent query strategy for developing.
- I want to use Linq for Activerecord.
- Do not want to expose IQueryable or any dependecies on the repo.
Note: im not going ddd. I want to benefit from this because of the previous reasons.
Now comes the questions to my mind:
- If i go for the generic repository, i have the problem with dealing with an entity that not suports deleting, to name some example. I could expose an interface and make this explicit, but this sound like solving the problem the dirty way.
- How to Query?. This really really confuses me.
Initially i sketched the Query method in the repository to accept a Expression<Func<T, bool>>. What do you think?
There are a lot of stuff going around the Specification Pattern, and i don't get difference well? This one really confuses me. Is seems more a domain concept, and sometimes querying is not.
Query Objects: as far as i understand, i'll need some object that translate the query object recieved in my repo. This sounds too much work. Im missing something?
Another option is to expose GetOutstandingProducts, but i need a IProductRepository and base it on the generic one. I like this one: expresses better the contract, and has more sense a controller that requires this on the constructor than a IRepository. Now, with the last option: update, create and delete in the generic repo will be super-simple (something like ActiveRecordMediator.Update(..); and this don't smeel good. Is seems like it's not good reuse, it's more an additional level of abstraction.
Hope you guys can throw me some ligth on this. Is seems like a very simple concept, and i can't get it.
Thanks for reading.