In true Sitecore fashion, I wanted to quickly get an initial working version of Dynamic Sites Manager out the door for the Sitecore 8.2 Initial Release. Tonight, I went back into the code and realized that the SiteManager.Providers property has been marked obsolete, something that wasn’t very clear in the Release Notes. This means at some point in a later release, SiteManager.Providers will become a breaking change.
As such, I wanted to go ahead and clean that up. Instead of using this property, I am now calling the service using dependency injection. Originally, I wasn’t using a constructor for my SwitcherSiteProvider class, but now I am.
private readonly ProviderHelper<SiteProvider, SiteProviderCollection> _providerHelper; public SwitcherSiteProvider(ProviderHelper<SiteProvider, SiteProviderCollection> providerHelper) { _providerHelper = providerHelper; }
However, there’s one more step that I have to take. I have to tell Sitecore’s Configuration Factory that it needs to resolve this class for dependency.
<siteManager> <patch:attribute name="defaultProvider">switcher</patch:attribute> <providers> <add name="dynamic" type="Sitecore.SharedSource.DynamicSites.Sites.DynamicSitesProvider, SharedSource.Sitecore.DynamicSites" siteConfig="dynamicsites" checkSecurity="false" /> <add name="switcher" type="Sitecore.SharedSource.DynamicSites.Sites.SwitcherSiteProvider, SharedSource.Sitecore.DynamicSites" checkSecurity="false" resolve="true" /> </providers> </siteManager>
The magic is in the addition of the resolve=”true” attribute on my provider.
Time to use the hell out of the built in dependency injection with Sitecore 8.2!
Get Dynamic Sites Now
Leave a Reply