jorge07 / symfony-6-es-cqrs-boilerplate

Symfony 6 DDD ES CQRS backend boilerplate.
MIT License
1.07k stars 187 forks source link

Item and Collection class #131

Closed murthog1337 closed 4 years ago

murthog1337 commented 4 years ago

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

jorge07 commented 4 years ago

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

jorge07 commented 4 years ago

Closing. Feel free to reopen if needed