#1 2016-06-27 20:00:45

gribeiro
Member
Registered: 2016-06-27
Posts: 3

MVC Best Practices and Sample

Hi, there!

ME and my colleagues are looking for a sample using MVC using mORMot framework. We´ve stumbled upon example 30, but there we have coupled persistence logic to the controller which is not compatible with MVC separation of concerns. Could anyone help us providing a sample respecting MVC SoC? Many thanks in advance.


Regards,


Geovanny Ribeiro


A humble guy passionate about his family and technology!

Offline

#2 2016-06-27 21:21:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: MVC Best Practices and Sample

Persistence is handled by the ORM, and logic in the controller, aren't they?

You may write a persistence service to encapsulate the ORM, if you prefer.

Offline

#3 2016-06-28 11:27:11

gribeiro
Member
Registered: 2016-06-27
Posts: 3

Re: MVC Best Practices and Sample

Hi, Arnaud!

That´s exactly we were talking about yesterday at the office! By the way, we were thinking about database transactions as well. Maybe we could use a service layer to start transactions when multiple persistence operations are needed. What would you suggest? Two layers: service & repository? Actually we still in doubt about one thing: in example 30 MVC we have the Blog controller inheriting from TMVCApplication which clearly contains persistence logic (through RestModel class) if we create a repository inheriting from TMVCApplication this repository would be accessible through web as well (this would be an undesirable side effect)? Many thanks for your promptly reply. Good. day!


A humble guy passionate about his family and technology!

Offline

#4 2016-06-28 11:50:16

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: MVC Best Practices and Sample

Transactions have to be done explictly at service level.
Using a two-phase commit, e.g. as defined with the Persistence service (Commit/Rollback) as defined in the User Persistence DDD units, and detailed in the doc. RTFM may help.

The persistence logic in sample 30 is defined in the MVCModel.pas unit.
It is clearly uncoupled from the main MVCViewModel.pas unit.
The ORM methods are called directly, and hosted in the main RestMode: TSQLRestServer instance, but it definitively does make sense, in this case.

Anyway, you should NOT inherit your repository from TMVCApplication.
It does not make sense. This would be even worse than the current implementation.
The repository IS a service.
Define an interface, injected in TMVCApplication as a separated persistence class.
You may define the repository service in the Model unit, together with ORM classes - for the sample 30, the repository service may have been defined in MVCModel.pas unit.

Offline

#5 2016-06-29 13:12:56

gribeiro
Member
Registered: 2016-06-27
Posts: 3

Re: MVC Best Practices and Sample

Hi, Arnaud!

Thanks again for your promptly reply. Don´t get me wrong based on my questions that´s because I´m acting as a translator for the Delphi dev team at my office. I´m a Java dev not a Delphi one, ok? The guys asked me to question you about how they can customize the http routes because the basic ones are based on models, but if you need to create custom routes? Regards.


A humble guy passionate about his family and technology!

Offline

#6 2016-06-29 16:25:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: MVC Best Practices and Sample

No, the MVC routes are based on the interface method names.

Offline

Board footer

Powered by FluxBB