2013-10-07 63 views
1

遷移到NServiceBus 4(從3.3.7到4.0.5)後,我試圖運行我的自定義佐賀Persister。我註冊它在容器(一個我在整個Web應用程序中使用),但在應用程序啓動時,我得到異常:NServiceBus 4和自定義SagaPersister

[ComponentResolutionException:看起來你正在試圖解決依賴的組件(直接或間接)上作爲生活方式的組件是PerWebRequest。當前執行的代碼不在Web請求範圍中。分析您的依賴關係並更改它們的生活方式(對signletons)或其依賴關係。] c:\ tfs \ Main \ src \ AppName2中的CustomApp.Mapping.WebRequestFallingBackToCallContextScopeAccessor.GetScope(CreationContext上下文) \ CustomApp \ CustomApp.Mapping \ WebRequestFallingBackToCallContextScopeAccessor.cs:40 Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.GetScope(CreationContext上下文)33 Castle.MicroKernel.Lifestyle.ScopedLifestyleManager.Resolve(CreationContext上下文,IReleasePolicy releasePolicy)84 城堡。 MicroCernel.Handlers.DefaultHandler.ResolveCore(CreationContext上下文,布爾requireDecommission,布爾instanceRequired,負擔&負擔)+282 Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext上下文,B oolean instanceRequired)35 Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext上下文中,ComponentModel模型,DependencyModel依賴性)170 Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext上下文中,ISubDependencyResolver contextHandlerResolver,ComponentModel模型,DependencyModel依賴性) 38個 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate構造,CreationContext上下文)430 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext上下文)52 Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext上下文)+30 Castle.MicroKernel.ComponentActivator.AbstractComponentAc tivator.Create(CreationContext上下文,爐料負擔)27 Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext上下文,布爾trackedExternally)57 Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext上下文,IReleasePolicy releasePolicy)29 Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext上下文中,布爾requiresDecommission,布爾instanceRequired,爐料&負擔)282 Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext上下文中,布爾instanceRequired)35 Castle.MicroKernel。 DefaultKernel.ResolveComponent(IHandler處理程序,類型服務,IDictionary additionalArguments,IReleasePolicy策略)+154 Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernel Internal.Resolve(Type service,IDictionary arguments,IReleasePolicy policy)+74 NServiceBus.Config.DisplayInfrastructureServicesStatus.Run()in c:\ BuildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Config \ InfrastructureServices.cs:163 System .Collections.Generic.List 1.ForEach(Action 1 action)+14013700 NServiceBus.Configure.Initialize()in c:\ BuildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Configure.cs:374 NServiceBus.Configure.CreateBus()in C:\ BuildAgent \ work \ d4de8921a0aabf04 \ src \ NServiceBus.Core \ Configure.cs:307 c:\ tfs \ Main \ src \ AppName2 \ CustomApp中的CustomApp.Web.Initialization.BusInstaller.Install(IWindsorContainer容器,IConfigurationStore存儲) \ CustomApp.Web \ Initialization \ BusInstaller.cs:56 Castle.Windsor.WindsorContainer.Install(IWindsorInstaller [] insta在Windows 2000或Windows 2000中,CustomApp.Web.WindsorContainerProvider.GetInitializedContainer()可以在c:\ tfs \ Main \ src \ AppName2 \ CustomApp \ CustomApp中使用。Web \ WindsorContainerProvider.cs:87 c:\ tfs \ Main \ src \ AppName2 \ CustomApp \ CustomApp.Web \ Global.asax.cs中的CustomApp.Web.MvcApplication.GetInitializedContainer():265 CustomApp.Web.MvcApplication.Application_Start ()in c:\ tfs \ Main \ src \ AppName2 \ CustomApp \ CustomApp.Web \ Global.asax.cs:139 CustomApp.Administration.Web.Global.Application_Start()in c:\ tfs \ Main \ src \ AppName2 \ CustomApp \ Administration \ CustomApp.Administration.Web \ Global.asax.cs:11

任何想法如何解決此問題?相同的代碼庫工作順利NServiceBus 3.3.7

編輯: 這是我如何初始化NSB:

Configure.Serialization.Xml(); 
Configure.Features.Enable<SecondLevelRetries>(); 
Configure.Features.Enable<TimeoutManager>(); 
Configure.Features.Enable<Sagas>(); 

var conf = Configure.With(assemblies) 
    .CustomConfigurationSource(new BusConfigSource(assemblies)) 
    .DefineEndpointName(ConfigurationManager.AppSettings["EndpointName"]) 
    .CastleWindsorBuilder(container) 
    .UseTransport<Msmq>() 
    .UseInMemoryTimeoutPersister() 
    .PurgeOnStartup(false) 
    .FileShareDataBus(WebConfigurationManager.AppSettings["NServiceBusFileShare"]) 
    .UnicastBus() 
    .LoadMessageHandlers() 
    .MsmqSubscriptionStorage(); 
conf.Configurer.ConfigureComponent<CustomSagaPersister>(DependencyLifecycle.InstancePerCall); 
conf.CreateBus().Start(() => Configure.Instance.ForInstallationOn<Windows>().Install()); 

我也試圖與manualy的辦法增加我的CustomSagaPersiter到容器中,而無需調用

conf.Configurer.ConfigureComponent<CustomSagaPersister>(DependencyLifecycle.InstancePerCall); 

但結果是一樣的。

+0

你能提供你的註冊碼嗎? –

+0

Chris,我添加了init代碼。 – stachu

+0

請創建一個問題https://github.com/Particular/NServiceBus/issues/new並附上一個repro鏈接? –

回答

0

經過一週的調查,似乎在我的應用程序容器初始化過程有點奇怪。容器在NSB啓動期間未完全初始化,因此某些依賴關係的解決方案是不可能的,這是由於提到的異常造成的。

我解決了這個問題,使得我的CustomSagaPersister的依賴項可選(屬性注入),所以當通過DisplayInfrastructureServicesStatus解析CustomSagaPersister時,應用程序不會崩潰(依賴項不會被注入,但由於我們只檢查註冊的內容,它,這是好的)。

另一個解決方法是從NSB中刪除DisplayInfrastructureServicesStatus並自定義編譯它。