0

Which layer should hold pagination information? (Page Size, Page Number), Eg say 100 products, 5 product per 20 pages. User can type in API url layer.

api/Product?Page=1&Limit=2&ColumnSort=Name

Our current architecture is this:

DomainClasses --> (Domain Repository Place in DTO) ---> Business Application Layer --> (Application Method Stored in --> APIs andViewModels

There is a discussion where to hold pagination information, Typical Application can call many repositories. The discussion is going between DTOs and Application layer, just curious what good option is, and standard practice. Should the PagelModel class be in Generic class Application Service, or Generic Class DTO?

public class PageModel
{
    public int Page { get; set; }
    public int Limit { get; set; }
    public string ColumnSort { get; set; }

void BusinessApplicationService() : GeneralApplicationService
{
     ProductRepository()
     CustomerRepository(); 
     // Combine data etc,


void ProductDTO : GeneralDTO
{
      int ProductId {get;set;}
      string ProductName  {get;set;}
      float Amount {get;set;}

code/notes for paging/pagination

5

Pagination is not a domain concern. The domain layer typically does not care to know the number of records fetched from a persistence store.

It is a performance concern, specifically on the database side. And the only domain elements that deal with the database are repositories. So the way I see it, you need a mechanism to send it from the API request (or message) to the repository.

In the past, I have typically transported them to the application layer in a RequestObject DTO. These DTOs are usually constructed in controllers and passed into the Application Service layer. Application Service then gives them to repositories to use while executing queries.

You can optimize a few aspects at the repository level of course, maybe in your Base Repository class. You should have a default set at the repository level as a failsafe. You should also verify against absurd values and constrain min/max to a reasonable range.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.