Mahmoudz/Porto

Containers Sections Question

amaelftah opened this issue · 1 comments

can sections use other sections tasks or actions for example

i have a blog application with Admin Section & Moderator Section , and the Admin can list posts also Moderator can list posts , so in this case the sections can cross boundaries or i duplicate the logic of list posts tasks in both sections?

@Te7a-Houdini I don't know the very details of your issue, but if we just stick to the list posts question, you can do the following:

First, create new Container, called Post, which would hold all the post-related stuff (models, repositories, actions etc.).
Then, create an Action in that Container, e.g. GetPostListAction, which would fetch list of posts from database.
Finally, create a Request in Post/UI/API/Requests, that will call GetPostListAction. In Request, you can pre-validate whether user can call it or not, by checking if he/she is logged or has required permissions (is admin or moderator).

It is easier to split your application into containers that are model-related rather than permission-related. This means, that you can have Post container that have all Post-logic (Create, Update, Delete, Get), rather than Admin container and Moderator container.

By the way, you surely can call tasks/subactions from another container. Even more, sometimes it is unavoidable. If you have very general Container, like Mail, which is responsible for sending mails, you will need it frequently, when another container needs to send an email. Although it is better to keep Containers as separated as possible, in real world applications sometimes you have no other choice.

That is purely my opinion based on almost one year experience of using Porto in application (two of them are already in production). Let's now hope @Mahmoudz will not disagree. ;)