Sitecore配置工厂 - 具有多个参数的调用方法

时间:2013-04-04 14:30:16

标签: configuration dependency-injection sitecore factory

我已阅读John West关于网站配置工厂的文章(http://www.sitecore.net/unitedkingdom/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/02/The-Sitecore-ASPNET-CMS-Configuration-Factory.aspx

我尝试在自定义链接提供程序中实现它。

我希望Configuration Factory在链接提供程序中调用以下方法:

public void AddSitePath(String site, String path)
{
   // do stuff
}

这是配置(虽然我已尝试了几种类似的变体)。

<add name="sitecore" type="MyProject.Providers.CustomLinkProvider, MyProject" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false">
    <sitePaths hint="list:AddSitePath">
        <sitePath>
            <site>SiteOneName</site>
            <path>/product-range/</path>           
        </sitePath>
        <sitePath >
            <site>SiteTwoName</site>
            <path>/items-for-sale/</path>
        </sitePath>            
    </sitePaths>
</add >

我收到以下错误消息: 找不到添加方法:AddSitePath(类型:MyProject.Providers.CustomLinkProvider)

我怀疑问题在于我试图将2个参数传递给方法,当然,当我使用单个参数版本测试它时,它可以工作。

我需要在配置或类代码中进行哪些更改才能实现我的需求?

1 个答案:

答案 0 :(得分:1)

所以看起来你不能提供2个参数。相反,您传入一个XmlNode对象,其中包含您需要的所有内容。您必须从方法中的XmlNode中提取信息。

有些事情:

public void AddSitePath(XmlNode arg)
{
   // pick apart the XmlNode and do stuff
}
<sitePaths hint="raw:AddSitePath">
    <sitePath site="SiteNameOne" path="/product-range/">
    <sitePath site="SiteNameTwo" path="/items-for-sale/">            
</sitePaths>

请注意,您必须使用'raw'前缀而不是'list'