我如何为 Sitecore 8.2.5 配置数据提供程序,以便 Sitecore 内核调用其构造函数?

How do I have to configure a dataprovider for Sitecore 8.2.5 so its constructor is called by the Sitecore Kernel?

我们从 Sitecore 8.1 升级到 8.2.5 并且我们使用的数据提供者之一,但我们自己没有编码,它不再工作了。

到目前为止,我们可以将问题追溯到 Sitecore 内核在页面初始加载时从未调用的构造函数,这导致数据提供程序无法正常工作。

我们没有更改配置文件中的任何内容,但据我们所知,8.2 已经更改了依赖注入的工作方式。

配置文件条目:

<sitecore database="SqlServer">

<events timingLevel="none">
    <!-- Dataprovider Events -->
    <event name="item:saved">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnItemSaved"/>
    </event>
    <event name="item:saved:remote">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnItemSavedRemote"/>
    </event>
    <event name="publish:end">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnPublishComplete"/>
    </event>
    <event name="publish:end:remote">
        <handler type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProviderNotification, Company.WCMS.PROJECT.Common" method="OnPublishComplete"/>
    </event>
    <!-- /Dataprovider Events -->
</events>

<pipelines>

    <publishItem>
    <processor patch:before="processor[@type='Sitecore.Publishing.Pipelines.PublishItem.DetermineAction, Sitecore.Kernel']" type="Company.WCMS.PROJECT.Common.DataProvider.PublishPreventer, Company.WCMS.PROJECT.Common" />
    </publishItem>

</pipelines>

<!-- DataProvider -->
<dataProviders>
    <DynamicDataProvider type="Company.WCMS.PROJECT.Common.DataProvider.Dynamic.DynamicDataProvider, Company.WCMS.PROJECT.Common" patch:before="*[@type='Sitecore.Data.$(database).$(database)DataProvider, Sitecore.Kernel']"/>
</dataProviders>
<!-- /DataProvider -->

<!-- DATABASES -->
<databases>
    <database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
        <param desc="name">$(id)</param>
        <icon>Images/database_master.png</icon>
        <dataProviders hint="list:AddDataProvider">
        <dataProvider ref="dataProviders/main" param1="$(id)">
            <prefetch hint="raw:AddPrefetch">
            <sc.include file="/App_Config/Prefetch/Common.config" />
            <sc.include file="/App_Config/Prefetch/Master.config" />
            </prefetch>
        </dataProvider>

            <!-- Custom Changes Start -->
        <dataProvider ref="dataProviders/DynamicDataProvider"  patch:after="*[@ref='dataProviders/main']"/>
            <!-- Custom Changes End -->

        </dataProviders>
    </database>
    ...
<databases>

我们的数据提供者的开始和构造函数:

using System.Reflection;
using Sitecore.Diagnostics;

namespace Company.WCMS.PROJECT.Common.DataProvider.Dynamic
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

using Sitecore.Caching;
using Sitecore.Collections;
using Sitecore.Data;
using Sitecore.Data.DataProviders;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;

using System.Collections.Concurrent;

using Name.Framework.ClassGenerator;

using Sitecore.Configuration;
using Sitecore.Events;
using Sitecore.Publishing;

public class DynamicDataProvider : DataProvider
{
    public static readonly ID OrginalFieldId = new ID("{f8ea7f10-f7f6-4c5a-a409-097728cc3f55}");

    private static readonly MD5CryptoServiceProvider Md5 = new MD5CryptoServiceProvider();
    private static readonly List<Action<IBaseSitecoreItem>> RefreshHandler = new List<Action<IBaseSitecoreItem>>();
    private static readonly List<Action<Database, bool>> ClearIdsHandler = new List<Action<Database, bool>>();

    private readonly HashSet<ID> rootItems = new HashSet<ID>();
    private readonly ConcurrentDictionary<ID, HashSet<ID>> realToFakeId = new ConcurrentDictionary<ID, HashSet<ID>>();
    private readonly ConcurrentDictionary<ID, FakeIdBucket> fakeCache = new ConcurrentDictionary<ID, FakeIdBucket>();
    private readonly List<IDynamicDataProvider> providers = new List<IDynamicDataProvider>();
    private readonly Dictionary<ID, List<IDynamicDataProvider>> tempalteToProviders = new Dictionary<ID, List<IDynamicDataProvider>>();

    private static string ItemIcon = Settings.GetSetting("Leister.Internet.DataProvider.ItemIcon", string.Empty);

    public static event Func<IBaseSitecoreItem, bool> RefreshItem;

    public DynamicDataProvider()
    {

        this.LoadProviders();

        RefreshHandler.Add(this.RefreshLocal);
        ClearIdsHandler.Add(this.ClearIds);
    }

RefreshHandler 始终为空,因为从不调用构造函数,这会阻止其他函数工作。

非常感谢任何帮助。

我们怀疑这是配置文件中的问题。 Sitecore 将数据库类型名称从 Database 更改为 DefaultDatabase,但我们没有注意到这一点,因此我们的补丁引用了错误的类型。我们对此进行了调整,现在可以使用了。