Reuse is good. That’s what we learn, so we all strive to reuse code, but sadly sometimes we over generalize and try to be too clever. I have had the suspicion that creating generic repositories that takes criteria/queries as input parameters is one such over generalization. Some things, in fact a lot of things, are worth making explicit.
As Greg Young points out in this excellent article, this over generalization can even hurt you when it comes to tackling performance at a later stage. It’s well worth the read. 🙂
3 replies on “DDD and generic repositories”
blog: DDD and generic repositories http://tinyurl.com/74oz2h
All things being equal, I would prefer specific repositories like this. However, this seems to explode the amount of configuration that I need to wire up stuff. There are ways around this again, but the once I’ve tried had the same problems with hiding intent as universal repositories have. Maybe I just need to use more autowiring…
I’m not sure auto wiring is the correct way. I see your argument about more configuration, but still think the explicitness trumps this.
I suspect your main concern here is how to handle these things the best way when you are writing tests. In the case of testing; as with so much else, the clue is to reuse and centralize set up code like this in a way that avoids it being all over the place.