Back to the topic of the conversation, I still have in my to-do list one last article about pagination and sorting. Hopefully, I'll get it done soon.
I'll try to summarize here what could be done briefly. I'll use some specific terminology discussed in the series above. Please read it before proceeding.
I'll use the shopping cart sample and only two boundaries (Sales and Marketing), to keep it simple. Adding more "boundaries" should not be a problem at all.
- The sales boundary owns the list of product IDs in the shopping cart and prices
- The marketing boundary owns product names and descriptions.
When the shopping cart is requested, sales intercept the request and loads the list of product IDs in the cart, then raises an event that is handled by marketing, and based on the list of IDs, names and descriptions are loaded and appended to the "composed" ViewModel.
Now, if a request like "GET /shopping-cart?page=0&pagesize=10" comes in, then Sales can apply pagination to the list of IDs in the cart. No other data are needed. When Sales raises the event, Marketing will add names and descriptions to an already paginated set of IDs. Marketing doesn't need to know anything about pagination. We could say that when composing lists only the "master" boundary (in this case Sales) is responsible for pagination.
If the request looks like the following "GET /shopping-cart?sortby=description" then Sales doesn't care at all. The composition process will behave exactly in the same way, when Marketing handles the event published by Sales it'll compose data in the ViewModel and once done sorts the list based on the description. The order of items in the shopping cart won't affect other boundaries.
This makes the sorting process simple if lists are sorted by one single property/attribute. A slightly more complex process needs to be applied in case the incoming request is something like "GET /shopping-cart?sortby=description,price". The result should be sorted by description and then by price, but description and price are in two different boundaries which bring on to the table te very annoying issue of boundaries dependencies. I'll discuss those in the blog post.
Thoughts?
.m