Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未注册默认实例,无法自动确定类型';epserver.Framework.Cache.IRequestCache_C#_Asp.net_Episerver_Quartz - Fatal编程技术网

C# 未注册默认实例,无法自动确定类型';epserver.Framework.Cache.IRequestCache

C# 未注册默认实例,无法自动确定类型';epserver.Framework.Cache.IRequestCache,c#,asp.net,episerver,quartz,C#,Asp.net,Episerver,Quartz,我有以下代码 [Quartz.DisallowConcurrentExecutionAttribute()] public class SearchIndexJob : IJob { private readonly ILog _Log = null; private SearchManager _SearchManager; public SearchIndexJob() { _Log = LogManager.GetLogger(GetTyp

我有以下代码

[Quartz.DisallowConcurrentExecutionAttribute()]
public class SearchIndexJob : IJob
{
    private readonly ILog _Log = null;
    private SearchManager _SearchManager;

    public SearchIndexJob()
    {
        _Log = LogManager.GetLogger(GetType());
    }

    #region IJob Members

    public void Execute(IJobExecutionContext context)
    {
        var container = new StructureMap.Container();

        IServiceConfigurationProvider services = new StructureMapConfiguration(container); 

        var locator = new EPiServer.ServiceLocation.StructureMapServiceLocator(container);
        var context2 = new EPiServer.ServiceLocation.ServiceConfigurationContext(HostType.WebApplication, services);

        new Mediachase.Commerce.Initialization.CommerceInitialization().ConfigureContainer(context2);

        container.Configure(ce =>
        {
            ce.For<IMarketService>().Use<MarketServiceDatabase>();
            ce.For<IMarket>().Use<MarketImpl>();
            ce.For<ICurrentMarket>().Singleton().Use<Mediachase.Commerce.Markets.CurrentMarketImpl>();
            ce.For<ISynchronizedObjectInstanceCache>().Singleton().Use<EPiServer.Events.RemoteCacheSynchronization>();
            ce.For<IObjectInstanceCache>().Use<HttpRuntimeCache>();
            //ce.For<ITypeScannerLookup>().Use<FakeTypeScannerLookup>();
            ce.For<IWarehouseRepository>().Singleton().Use<Mediachase.Commerce.Inventory.Database.WarehouseRepositoryDatabase>();
            ce.For<IChangeNotificationQueueFactory>().Singleton().Use<CommerceChangeQueueFactory>();
            ce.For<IPriceService>().Singleton().Use<PriceServiceDatabase>();
            ce.For<IPriceDetailService>().Use<PriceDetailDatabase>();
            ce.For<IWarehouseInventoryService>().Singleton().Use<WarehouseInventoryProxy>();
            ce.For<IInventoryService>().Singleton().Use<InventoryServiceProvider>();
            ce.For<IApplicationContext>().Use<FakeAppContext>();
            ce.For<CatalogConfiguration>().Use(CatalogConfiguration.Instance);
            ce.For<IRequiredMetaFieldCollection>().Singleton().Use<DefaultRequiredMetaFields>();
            ce.For<MetaDataContext>().Singleton().Use(() => CatalogContext.MetaDataContext);
            //ce.For<EventContext>().HybridHttpOrThreadLocalScoped().Use(eventContext);
            ce.For<FrameworkContext>().Use(() => FrameworkContext.Current);
            //ce.For<SqlContext>().Use(() => new SqlContext(BusinessFoundationConfigurationSection.Instance.Connection.Database));
            ce.For<IChangeNotificationManager>().Singleton().Use<ChangeNotificationManager>();

            ////ce.For<Mediachase.Commerce.Catalog.ICatalogSystem>().Singleton().Use(() => Mediachase.Commerce.Catalog.CatalogContext.Current);

            ce.For<IEventRegistry>().Use<EPiServer.Events.Clients.EventRegistry>();
            ce.For<IEventBroker>().Use<FakeEventBroker>();

            ce.For<Mediachase.Search.IndexBuilder>().Use<FakeIndexer>();
        });


        EPiServer.ServiceLocation.ServiceLocator.SetLocator(locator);

        string applicationName = context.JobDetail.Description;

        if (String.IsNullOrEmpty(applicationName) || applicationName == "all") // index all applications
        {
            AppDto dto = AppContext.Current.GetApplicationDto();

            foreach (AppDto.ApplicationRow row in dto.Application)
            {
                IndexApplication(row.Name);
            }
        }
        else
        {
            IndexApplication(applicationName);
        }
    }
    #endregion

    void IndexApplication(string applicationName)
    {
        _Log.Info(String.Format("Creating Search Manager for \"{0}\" Application.", applicationName));
        _SearchManager = new SearchManager(applicationName);

        _Log.Info("Created Search Manager.");

        try
        {
            _SearchManager.SearchIndexMessage += new SearchIndexHandler(_SearchManager_SearchIndexMessage);
            _SearchManager.BuildIndex(true);
        }
        catch (Exception ex)
        {
            _Log.Error("Search Manager Failed.", ex);
        }
    }

    void _SearchManager_SearchIndexMessage(object source, SearchIndexEventArgs args)
    {
        _Log.Info(String.Format("Percent Complete: {0}%, {1}", Convert.ToInt32(args.CompletedPercentage), args.Message));
    }

}

public class FakeEventBroker : IEventBroker
{
    public bool Enabled { get; set; }

    public System.Threading.Tasks.Task RaiseEventAsync(Guid eventId, Object parameter)
    {
        return null;
    }

    public event EventHandler<EventReceivedEventArgs> EventReceived;

    public event EventHandler<EventMissedEventArgs> EventMissed;
}
public class FakeAppContext : IApplicationContext
{
    public bool HasContentModelTypes { get; set; }

    public bool DisableVersionSync { get; set; }
}

public class FakeIndexer : Mediachase.Search.IndexBuilder
{
    public FakeIndexer() : base("","","")
    {

    }
}
[Quartz.DisallowConcurrentExecutionAttribute()]
公共类SearchIndexJob:IJob
{
私有只读ILog _Log=null;
private SearchManager\u SearchManager;
公共SearchIndexJob()
{
_Log=LogManager.GetLogger(GetType());
}
#区域IJob成员
public void Execute(IJobExecutionContext上下文)
{
var container=new StructureMap.container();
IServiceConfiguration提供程序服务=新结构映射配置(容器);
var locator=新的epserver.ServiceLocation.StructureMapServiceLocator(容器);
var context2=新的epserver.ServiceLocation.ServiceConfigurationContext(HostType.WebApplication,services);
新建Mediachase.Commerce.Initialization.CommerceCInitialization().ConfigureContainer(context2);
container.Configure(ce=>
{
ce.For().Use();
ce.For().Use();
ce.For().Singleton().Use();
ce.For().Singleton().Use();
ce.For().Use();
//ce.For().Use();
ce.For().Singleton().Use();
ce.For().Singleton().Use();
ce.For().Singleton().Use();
ce.For().Use();
ce.For().Singleton().Use();
ce.For().Singleton().Use();
ce.For().Use();
ce.For().Use(CatalogConfiguration.Instance);
ce.For().Singleton().Use();
ce.For().Singleton().Use(()=>CatalogContext.MetaDataContext);
//ce.For().HybridHttpOrthReadLocalScope().Use(eventContext);
ce.For().Use(()=>FrameworkContext.Current);
//使用(()=>newSQLContext(BusinessFoundationConfigurationSection.Instance.Connection.Database));
ce.For().Singleton().Use();
////ce.For().Singleton().Use(()=>Mediachase.Commerce.Catalog.CatalogContext.Current);
ce.For().Use();
ce.For().Use();
ce.For().Use();
});
epserver.ServiceLocation.ServiceLocator.SetLocator(定位器);
字符串applicationName=context.jobdail.Description;
if(String.IsNullOrEmpty(applicationName)| | applicationName==“all”)//为所有应用程序编制索引
{
AppDto dto=AppContext.Current.getApplicationTo();
foreach(dto.Application中的AppDto.ApplicationRow行)
{
索引应用程序(行名称);
}
}
其他的
{
IndexApplication(应用程序名称);
}
}
#端区
无效索引应用程序(字符串应用程序名称)
{
_Log.Info(String.Format(“为\“{0}\”应用程序创建搜索管理器。”,applicationName));
_SearchManager=新的SearchManager(应用程序名称);
_Log.Info(“已创建搜索管理器”);
尝试
{
_SearchManager.SearchIndexMessage+=新的SearchIndexHandler(\u SearchManager\u SearchIndexMessage);
_SearchManager.BuildIndex(true);
}
捕获(例外情况除外)
{
_Log.Error(“搜索管理器失败”,例如);
}
}
void\u SearchManager\u SearchIndexMessage(对象源,SearchIndexEventArgs)
{
_Log.Info(String.Format(“完成百分比:{0}%,{1}”,Convert.ToInt32(args.CompletedPercentage),args.Message));
}
}
公共类FakeEventBroker:IEventBroker
{
已启用公共bool的{get;set;}
public System.Threading.Tasks.Task RaiseEventAsync(Guid eventId,对象参数)
{
返回null;
}
公共事件处理程序EventReceived;
公共事件处理程序EventHandler EventMissed;
}
公共类FakeAppContext:iaApplicationContext
{
公共bool HasContentModelTypes{get;set;}
public bool DisableVersionSync{get;set;}
}
公共类FakeIndexer:Mediachase.Search.IndexBuilder
{
public FakeIndexer():base(“,”,“”)
{
}
}
我得到了这个错误 “未注册任何默认实例,并且无法自动为类型'epserver.Framework.Cache.IRequestCache'确定”

在这一行“_SearchManager.BuildIndex(true);”


有什么想法吗?

很难说,但我认为您需要在容器中注册IRequestCache

container.Configure(ce=>
{
ce.For().Use();
ce.For().Use();
ce.For()。使用();//或任何您需要的实现
...
}

很难说,但我假设您需要在容器中注册IRequestCache

container.Configure(ce=>
{
ce.For().Use();
ce.For().Use();
ce.For()。使用();//或任何您需要的实现
...
}

计划作业正在尝试初始化商业,您很可能需要修复比IRequestCache(包括DBContext)更多的问题,请参阅此处的集成示例。

计划作业正在尝试初始化商业,您很可能需要修复比IRequestCache(包括DBContext)更多的问题,请参阅此处的集成示例

container.Configure(ce =>
{
    ce.For<IMarketService>().Use<MarketServiceDatabase>();
    ce.For<IMarket>().Use<MarketImpl>();
    ce.For<IRequestCache>().Use<NoRequestCache>(); // or whatever implementation you need
    ...
}