jeudi 12 janvier 2017

Where to validate pagination logic in domain driven design?

In DDD, where should validation logic for pagination queries reside? For example, if the service layer receives a query for a collection with parameters that look like:

struct Page {
   Limit int
   Offset int
}


// service layer
func getCollection(p *Page) (pages, error) {

}

and I want to enforce a "no Limit greater than 100" rule, does this rule belong in the Service layer or is it more of a Repository concern?

At first glance it seems like it should be enforced at the Repository layer, but on second thought, it's not necessarily an actual limitation of the repository itself. It's more of a rule driven by business constraints that belongs on the entity model. However Page isn't really a domain entity either, it's more a property of the Repository layer.

To me, this kind of validation logic seems stuck somewhere between being a business rule and a repository concern. Where should the validation logic go?

Aucun commentaire:

Enregistrer un commentaire