Friday, 30 January 2015

Sitecore 8's SitecoreSiteProvider Class

I've previously written about my interest in experimenting with Sitecore's SiteProvider, and I'm pleased to see that a new class has been introduced in Sitecore 8 that helps with that.

The SitecoreSiteProvider class is inherited from the abstract SiteProvider. It acts as an aggregator for any other registered site providers you have in your instance. The abstract SiteProvider has 2 required override methods:

SiteCollection GetSites()
When you call GetSites on SitecoreSiteProvider, that method is called on all other registered site providers, and the concatenated results are returned.

Site GetSite(string siteName) 
When you call GetSite on SitecoreSiteProvider, the results from that method on all other site providers are combined and FirstOrDefault is returned.

SitecoreSiteProvider is set as the default in Sitecore 8, with the old ConfigSiteProvider regsitered as one of its "targets". I like this new approach and hope to see people doing interesting things with it in future.