Wednesday, April 4, 2012

Inside the MvcSiteMapProvider - Part 1

I have recently worked a lot with the MvcSiteMapProvider, a great project created by Maarten Balliauw, which greatly simplifies navigation and sitemap.xml generation. But how is it done? This is of great importance to good performance, wrongly implemented it can make you site pretty slow.
Because of this I decided to create a series of in-depth posts about the internals of the MvcSiteMapProvider, and give some advices on how to improve performance. The first part is about how the main part of the provider is implemented.


The DefaultSiteMapProvider

The DefaultSiteMapProvider implements the abstract StaticSiteMapProvider implemented in .NET. The reason of choosing this as the base class instead of the abstract SiteMapProvider class, is that a XML sitemap file is recommended as a starting point, as this is much easier to control (this is my recommendation, not the authors). You can still generate a dynamic part using DynamicNodeProviderBase which is explained on the “Dynamic sitemaps” wiki page. If you don’t want to use the sitemap file, checkout “Defining sitemap nodes in code”.
The DefaultSiteMapProvider is the class tasked with generating the sitemap and reading the custom settings from the web.config file. Except for this the class doesn’t do much, as the hard work is done by the StaticSiteMapProvider from .NET.
The “Registering the provider” wiki page on GitHub provides a good overview of the possible settings, default values and their meaning. Starting from version 3.2.2, the following settings can be defined indirectly using the dependency injection facilities in MVC:
  • nodeKeyGenerator
  • controllerTypeResolver
  • actionMethodParameterResolver
  • aclModule
  • siteMapNodeUrlResolver
  • siteMapNodeVisibilityProvider
  • siteMapProviderEventHandler
Even when using dependency injection the value defined in web.config will be used. If no value is defined the dependency injection will take place, and if no injection is defined, the default classes will be used.

No comments:

Post a Comment