Take the 2-minute tour ×

I am developing an app in ddd maner. So I have a complex domain model. Suppose I have a Fare object and Airline. Each Airline should contain several or much more Fares.

My UI should represent Model (only small part of complex model) as a list of Airline, when the user select the Airline, I must show the list of Fares. User can filtering the Fares (by travel time, cost, etc.).

What is the appropriate place for filtering Fares and Airlines?

I am assuming that I should do it in ViewModel. Like: My domain model has wrapped with Service Layer -> UI works with ViewModel -> ViewModel obtain data from Service Layer filtering it and create DTO objects for UI. Or I'm wrong?

share|improve this question
his similar post at SO: stackoverflow.com/questions/13970436/… –  jgauffin Dec 20 '12 at 14:55

2 Answers 2

If there is a substantial amount of data to filter, then consider passing the "filter" query up through the stack so that it is a database query. This will minimize the amount of data passing between your database (assuming you have one) and your code.

On the other hand, if you need to filter data that are already in memory, and your code is all in a single process, then you can do so at any point: you are only passing pointers after all. But if you are considering refactoring your service layer into an actual service, running separately from the UI code, then you want the filtering to be in the service layer so that you can again minimize the data traffic between layer boundaries.

share|improve this answer

Generally DDD and CQRS go hand in hand, so this would be the query portion of CQRS. The way I've always understood CQRS and DDD together is that the application service should have focused queries. If you're filtering at the UI level (on the initial get, not client side) then you would seem to be breaking this separation of concerns as you're now doing business logic in the UI. Ideally the filtering should be a very simple query. But as always DDD and CQRS are but tools, do what works.

share|improve this answer

Your Answer


