Monday, February 5, 2018

Using MVC Areas with your Sitecore Helix solution

One of the great features of a Sitecore solution which uses the Helix approach is the modular architecture of all of your features. This allows for logical grouping of features by type or perhaps website (in a multi-site implementation).

However as a solution expands, it may become possible for there to be conflicts on controller names. Therefore the use of MVC areas is one way to partition the controllers before any conflicts happen. In my case I was building a rather large helix solution for a multi-site commerce implementation, where there was likely to be controllers with duplicate names. In this case I was creating a feature project for each website (along with a common) to reduce build time (as opposed to logically grouping features, such as an Account feature project for all sites).

This is where areas came in handy, inside the project it was simple enough to add one.

Visual Studio -  Add MVC Area
Inside Sitecore it's as simple as defining the area on the controller rendering.

Sitecore controller rendering - define the area
In the example above, there is the Testing area which contains the Common Feature Controller with a Test view.

Of course using MVC areas is not always relevant for every Sitecore implementation, however it is a good tool to have handy when required.

No comments:

Post a Comment