2017-03-27 4 views
0

、私は次のコードデフォルトなしのインスタンスが登録されていないと、自動的にタイプのために決定することができない「EPiServer.Framework.Cache.IRequestCache

[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("","","") 
    { 

    } 
} 

を持っていると私は、このエラー 「いいえ、デフォルトのインスタンスが登録されていないとすることはできません取得タイプ "EPiServer.Framework.Cache.IRequestCache"のために自動的に決定される

"_SearchManager.BuildIndex(true);"

アイデア?

答えて

0

伝えるのは難しいですが、私はあなたのコンテナ

すなわちでIRequestCacheを登録する必要がありますと仮定します

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

ジョブのスケジュールは、おそらくあなたがここに統合サンプルを参照してください、DBContext含むIRequestCache、より多くの問題を解決するために必要となる、Intializeコマースしようとしています。 GIT Integration Sample

関連する問題