jorge07/symfony-6-es-cqrs-boilerplate

Item and Collection class

murthog1337 opened this issue · 2 comments

Hi, i don't understand the purpose of Item class and Collection class. Why using this classes instead of passing directly the data from infrastructure to application ui, it's like you guys using this as middleware to have a presentable data but i don't get it, i mean it doesn't make sense.

Can someone explain the reason please?

Thank you

Hi @murthog1337,
We're using this as contract for the read model. So we've a normalized way to handle resources and collections, making easier to manage pagination in UI for example. By doing this UI doesn't need to understand each query response, but just the contracts for resources and collections. This also enables the use of formatters that can convert this contract into xml or json api in the UI layer. Example here https://github.com/jorge07/symfony-4-es-cqrs-boilerplate/blob/master/src/UI/Http/Rest/Controller/QueryController.php#L23. The reason why the go through application layer for the queries and not directly to infrastructure is that we can use Middlewares in the query bus for things like cache or authorization.
Hope it helps you and in case you disagree, happy to read your arguments, sure can improve this.
Regards

Closing. Feel free to reopen if needed