Use Wrapper instead of Entity Action?

I have all my entities set to Expose ReadOnly and Public Yes.

Taking references from this post, https://www.outsystems.com/forums/discussion/48437/how-do-i-do-to-create-a-createorupdateresourcewrapper/

1) What are the advantages of using Wrapper instead of directly calling the entity action?

The only thing i can think of is that i can add validation logic inside the wrapper. 

2) Assuming, i have both the web and mobile apps using the same entity Wrapper, do i put the business logic inside of the wrapper as well??

Solution

Hi there,

1) If you use a wrapper and set the entity to Expose ReadOnly yes, you have one action each to manipulate (Create, Update, Delete) the entity. Every application/consumers need to use this action, because this is the only way. This will improve maintability and prevents that the entity is manipulated in a wrong way. Also a lot easier to add business logic and validations.

2) Yes if the business logic is the same. Otherwise create separate actions to validate the business logic for web and mobile.

Regards,

Thomas Druif

Solution

Hey,

I actually had a real life example of the advantages of a single set of CRUDs a few months ago at a client.

We had an Entity that was not read-only and set to public, and so we had several Applications writing records to the Entity. These records had several columns with basic audit information (who created the record, updated it, and when it happened), and in several instances, this information was not being correctly filled out - which lead to having to discuss the issue with multiple teams and having to involve multiple developers in order to find out which application was not correctly inserting this data, and where.

This can all be avoided by creating a central way of interacting with the data stored inside the Entity - by not using read only you are allowing others to insert data in the Entity without any control. Using the audit information example again, you have no way to ensure the audit is not being falsified, for instance.

EnthusiaticNewbie wrote:

I have all my entities set to Expose ReadOnly and Public Yes.

Taking references from this post, https://www.outsystems.com/forums/discussion/48437/how-do-i-do-to-create-a-createorupdateresourcewrapper/

1) What are the advantages of using Wrapper instead of directly calling the entity action?

The only thing i can think of is that i can add validation logic inside the wrapper. 

2) Assuming, i have both the web and mobile apps using the same entity Wrapper, do i put the business logic inside of the wrapper as well??


I think this page is a good starting point to look at how to better design the architecture and deal with data abstractions.

https://success.outsystems.com/Support/Enterprise_Customers/Maintenance_and_Operations/Designing_the_architecture_of_your_OutSystems_applications/02_Translating_business_concepts_into_application_modules

That being said, architecture design is not a one time exercise. It should evolve over time as applications grow and more business concepts are realized.


Good morning everyone!

Great discussion here :) adding more color to what was mentioned previously, you can also check this recently published article form an OS MVP https://medium.com/@jmjames/outsystems-crud-wrapper-basics-e9a577a3e044.


Vera

Dear Afonso and Thomas 

Thank you for assisting me with my queries. Unfortunately i can only mark one as the solution. There is no way to mark a second one as equally good. 


Dear Boney

I am aware of the 4 layers canvas but sometimes i am stuck at deciding when/how to do certain things that follow design pattern yet does not take too long route to achieve the same thing. 


Dear Vera

Thank you for the article. I like it! :)

Hello All, 


Created an idea to have the CRUD wrapper generated by the platform on making the "Expose Read Only" to yes for an entity. 

If the idea gets enough likes maybe OutSystems will roll this out in the upcoming releases. 


Regards

Amal 

EnthusiaticNewbie wrote:

Dear Afonso and Thomas 

Thank you for assisting me with my queries. Unfortunately i can only mark one as the solution. There is no way to mark a second one as equally good. 


Dear Boney

I am aware of the 4 layers canvas but sometimes i am stuck at deciding when/how to do certain things that follow design pattern yet does not take too long route to achieve the same thing. 


Dear Vera

Thank you for the article. I like it! :)

Not an issue! We're all here to help each other, glad that you got good info.