c# - DDD - How to implement high-performing repositories for searching -
i have question regarding ddd , repository pattern.
say have customer repository customer aggregate root. & find methods return populated aggregate, includes objects address, etc. good. when user searching customer in ui, require 'summary' of aggregate - flat object summarised information.
one way deal call find method on repository normal, , in application layer, map each customer aggregate customersearchresult / customerinfo dto, , send them client.
but problem performance; each customer aggregate may require multiple queries populate of associations. if search criteria matched 50 customers, that's quite hit on db potentially retrieving data i'm not going need.
the other issue may wish include summarised data customer outside of customer's aggregate root boundary, such date of last order made example. order has it's own aggregate , therefore customer's order information have call orderrepository, degrading performance.
so think i'm left 2 options:
add additional find method customerrepository returns list of these summary objects doing 1 efficient query.
create purpose built readonly customerinforepository, has find method described in 1.
but both of these feel i'm going against principles of ddd. repositories inherit generic base: repository t : iaggregateroot. these summary info object not aggregates, , of different type t, #1 goes against design.
perhaps #2 create abstract searchrepository without iaggregateroot constraint?
there many similar scenarios in domain.
how implement scenario?
thanks, dave
update
after reading theo's answer, think go option #2 , create specialised searchrepository within infrastructure geared towards these scenarios. application layer (wcf services) can call these repositories populate summary dtos directly rather mapping domain entities dtos.
**** update 2 ****
although asked on year ago thought i'd add i've since discovered cqrs aimed @ solving exact problem. udi dahan (http://www.udidahan.com/) , greg young (http://codebetter.com/gregyoung/) have written lot it. if creating distributed application ddd, cqrs you!
i think want display summarized information. these bits of summarized information no entities or value objects of domain model. information, nothing more.
it showing reporting information. if deal such things, not stick pure ddd approach. suggested options ok, because it's getting job done. ddd should not treated dogma. think outside box. loosen bit ddd.
but aware creating informational values outside model displaying purpose. if user selects 1 bit of information make operation (which defined in domain model), need extract identifier informational values , pull out entity/value object/aggregate repository.
i recommend video: eric evans: i've learned ddd since book. if read book, should see whole video. pay close attention @ time 30:00 eric evans himself talks aggregates , refers problem have.
Comments
Post a Comment