How to get the deprecated LinkManager Provider and Providers now

14 juni 2017 om 00:00 by Menderes Demir - Post a comment

I'm happy to introduce our new website, which is based on the Helix conventions and principles. The website is built on Sitecore 8.2 rev. 170407.

For better management and Search Engine Optimization, I of course have added our Url-Rewriter and Seo-Friendly-Url modules. As I was adding the Seo-Friendly-Url module I saw that the following properties are now deprecated:

  • LinkManager.Provider
  • LinkManager.Providers

After inspecting the Sitecore.Kernel.dll, I noticed that LinkManager.Provider is returning LinkManager.ProviderHelper.Value.Provider. This leads me to use:

ServiceLocator.GetRequiredResetableService<Sitecore.Configuration.ProviderHelper<LinkProvider, LinkProviderCollection>>();

So I can get the Provider:

var providerHelper = ServiceLocator.GetRequiredResetableService<Sitecore.Configuration.ProviderHelper<LinkProvider, LinkProviderCollection>>();
var provider = providerHelper?.Value?.Provider;

I can also get the Providers property in the same way:

var providers = providerHelper?.Value?.Providers;