Several questions about developing my new MVC site (page types, repository)

Sylvain C. asked on May 30, 2019 00:12

Hi,
I just finished the MVC for developers training course and have several questions in mind. Even if I did a lot of MVC coding, in the world of CMSs, I only worked in the past with Drupal and Joomla and need to get adjusted to the Kentico way of doing things.

I am in a situation where I will have to redevelop a Kentico 12 MVC website and an editor will be taking care of the content. It won't be a marketing or commercial site, only publication of static articles, pictures or scientific documents.

My first question is related to page types:
In the training, a page type was created for every web page which also involved dealing with the corresponding classes, providers, DTOs, repositories, controller and views for each one... In my site, I will be dealing with 500~800 pages and won't be creating a page type for each page. 10-15 pages types will be probably the maximum. However, in my VS project, considering that each page will have a different route/URL, will I have to create 500~800 views and associated methods individually in my controllers?
From what I understood, repository, Dto, providers will be created and attached only to new page type hence the need of keeping their number as small as possible. Am I correct?
What is the best practice concerning the organization of pages types?
Should I use pages types inheriting from each others (one base page type for the title, etc...) or each page type should be standalone? Any recommendations?

Concerning new pages:
We will be sometimes in a situation where I won't be available to work on the site and when my editor will need to create need content. Typically, it will be adding a new page describing a new project or a new publication corresponding to a new route/URL. From the admin site, she will be able to create a new menu item for example, create a new page based on an existing page type, publish it but I don't see how she will be able to make it visible on the live site without having a developer creating the view and the controller. I explored the page builder but it seems to be only for adding new content into an existing pages for which views, controllers already exist.
It would be really a blocking issue for us if she couldn't add new pages without having me around.
Could you please explain how you process this kind of workflow?

MVC structure
I also wanted to know if any of you used different practices in organizing their MVC projects compared to the one described in the training. The separations of concern between the BLL and the Web projects make sense but the creation of interface and repository for each page types (one for doctors, one for the doctor section, etc) look a bit complicated especially if you have multiple page types. Did any of you explore a generic repository with a unit of work in order to have a single unit of operation/transaction (only one Get for example for all entities).

At last, just to verify that I understood correctly, you need to create the provider, DTO, repository and interface for each distinct page type but you need to create view and controller for each page having a different URL/route. Am I correct?

Sorry for this long email but it is new to me. I understand how kentico would be beneficial for us to build a fully customizable site but for the time being, it seems a bit tedious concerning the addition of just basic static content.

your feedback would be more than welcome

Cheers

Sylvain

Correct Answer

Trevor Fayas answered on May 30, 2019 04:18

Hey Sylvain,

Don't worry, it can be daunting to look to transition from Portal Engine to MVC and figure things out.

Page Types

A page type should contain really the elements that make up what it is. A blog article shoudl have a Title, Date, Abstract, etc. I'm not one to ever advocate that you put a lot of design-orientated elements into a Page type (like a list of banners). Kentico has Page relationships which are better suited for adding presentation type things to a page. I have a Relationships Extended module on NuGet for the Kentico Admin and MVC site to help also in creating these relationships and leveraging them.

While it may be good to have a base Page Type that contains things like the Page Title, Navigation Title, Abstract, etc that will populate your meta data on all pages, that's as far as i would go.

For the DTOs and such, this is Kentico's recommended practice, it's not required though, it helps with testing and I myself am going to work on learning it, but you can just make normal API calls if you wish in your controllers to get the data for your views.

All That being said, by default the Url is set at the Page Type level. You don't need to though, please see my January article on restoring Dynamic Routing so the Page type no longer defines the URL structure.

Also please be aware i have a Kentico Boilerplate that has many of these features, helpers, and other items already set up, which you can also contribute to if you wish. I encourage you to check it out!

New Pages

Yes in MVC, you do need to create the structure first for Editors to work in. You need to make sure whatever Action/View is rendered contains the markup for enabling Page Builder Widgets to be used. But after that, they can create new pages and add their widgets and stuff. In my boilerplate i have a "Generic widget page" which uses dynamic routing (the NodeAliasPath = Url) and is just a blank page with a widget zone, so it's 'free form.'

You can do similar. In the upcoming Kentico Service Pack, you can also add alternative Urls which redirect to the main url.

MVC Structure

As noted, while the DTO and structure is 'good' and beneficial from testing, it is extra work. You don't need to do this, you can simply do normal MVC.

Kentico's Document / Data Query Engine is pretty powerful as it is and allows for easy querying of data without writing any extra code.

At last

No, you do not need to create these for each page type if you do not want to use the DTO / Provider model. You can just use DocumentHelper.GetDocuments("My.Class") to get your documents. For routing, you either have to define the route that matches the Url Pattern of the Page type, or do what i often do and just put the Url Pattern of {% NodeAliasPath %} and use my dynamic routing to let the Url decide. We are in the processes of making a "Page Template" system where you can assign a Controller/Action/View to a page and then leverage that in the dynamic routing. It will be on the Boilerplate once done so keep an eye out for it.

Hope this helps! Check out my blog and resources section on my site http://www.devtrev.com, as well as the other Kentico MVP blogs!

1 votesVote for this answer Unmark Correct answer

Recent Answers


Sylvain C. answered on May 31, 2019 21:54 (last edited on May 31, 2019 23:45)

Thank you very much Trevor for your answer, it is very useful.

I am going to explore your boilerplate code especially the Generic widget page. It would be useful to me.

Cheers Sylvain

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.