Views hierarchy: Overview

April 01, 2009 Digital Experience

[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
 

As we have already mentioned in Sitefinity 3.6 module's backend is constructed from Views which are organized into a hierarchy, starting with the Control Panel class. This hierarchy allows us, as developers, several benefits when building modules, where two most important are:
  • Ability to manipulate the hierarchy at any level and work at once with multiple Views through their parent node
  • Ability to access the members of the parent Views (throughout the hierarchy) with a generic Host property
In this article we will examine these two properties of the hierarchical organization of the Views.

 


Ability to manipulate the hierarchy at any level


One of the biggest advantages of the hierarchical organization of the Views is the fact that we can take any given node of the hierarchy and replace or remove it with another View. Even more useful is the fact that we can reuse whole parts of the hierarchy in other modules and not just one single View. Following diagram illustrates these approaches.

As the diagram suggest, from the View hierarchy on the left we can remove the CommentsView and all the child view, such as CommentsList, CommentsInsert, CommentsEdit and CommentsPreview will be removed as well. The hierarchy beneath CommentsView will be completely change also if we replace the CommentsView View some other View.

 

Finally, we can add CommentsView View to another hierarchy (perhaps in a different module) and at the same time all the child views of the CommentsView will be moved to this new hierarchy. You can find out more about this approach in this article and also examine the sample products module to see the implementation where CommentsView View has been transplanted from Generic Content module to Products module.

 

Ability to access members of parent views


Since, both, ViewModeControl and ViewModeUserControl are generic types with generic arguments being the types of their hosts (parents), we are able to access the members of any parent Views along the hierarchy. Let us take a look at the following example:

The image above depicts an imaginary hierarchy of Views, where the top level View is Control Panel, followed by ShopsView and finally the last View in the current hierarchy is NewShopView. Since all the ViewModeControls have Host property, we can call the Host property to access the immediate parent, but since immediate parent is also a View mode control, we can also call it’s Host property to access its parent and so on.

 

So on the image, we see how we can access the ShopChainName property of the ShopsView, by simply calling this.Host.ShopCainName on NewShopView. If we need to go all the way to the top of the hierarchy, we can call this.Host.Host to get access to the members of the top View two nodes up the hierarchy.

The Progress Team