我已经用IProvideConfiguration
实现了一个类当我的总线创建时,它会被调用4次。因为那里有逻辑来做一些映射的收集 - 这个逻辑也执行了4次。我是否需要手动设置标记'Initialized'以防止它多次运行,或者我可以在NServiceBus中使用某些内容还是我使用了这个错误?
这些是导致4次调用的调用堆栈:
RZ.Integration.Server.dll!RZ.Integration.Config.NServiceBus.UnicastBusConfigProvider.GetConfiguration() Line 25 C#
NServiceBus.Core.dll!NServiceBus.SettingsExtentions.GetConfigSection<NServiceBus.Config.UnicastBusConfig>(NServiceBus.Settings.ReadOnlySettings settings) Unknown
NServiceBus.Core.dll!NServiceBus.Features.ForwardReceivedMessages.GetConfiguredForwardMessageQueue(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.ForwardReceivedMessages..ctor.AnonymousMethod__0_0(NServiceBus.Features.FeatureConfigurationContext config) Unknown
NServiceBus.Core.dll!NServiceBus.Features.Feature.CheckPrerequisites(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.HasAllPrerequisitesSatisfied(NServiceBus.Features.Feature feature, NServiceBus.Features.FeatureDiagnosticData diagnosticData, NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.ActivateFeature(NServiceBus.Features.FeatureActivator.FeatureState featureState, System.Collections.Generic.IEnumerable<NServiceBus.Features.FeatureActivator.FeatureState> featuresToActivate, NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.SetupFeatures(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Configure.Initialize() Unknown
NServiceBus.Core.dll!NServiceBus.Bus.Create(NServiceBus.BusConfiguration configuration) Unknown
RZ.Integration.Server.dll!RZ.Integration.Config.NServiceBus.UnicastBusConfigProvider.GetConfiguration() Line 25 C#
NServiceBus.Core.dll!NServiceBus.SettingsExtentions.GetConfigSection<NServiceBus.Config.UnicastBusConfig>(NServiceBus.Settings.ReadOnlySettings settings) Unknown
NServiceBus.Core.dll!NServiceBus.Features.TimeoutManagerBasedDeferral.GetTimeoutManagerAddress(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.TimeoutManagerBasedDeferral.Setup(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.ActivateFeature(NServiceBus.Features.FeatureActivator.FeatureState featureState, System.Collections.Generic.IEnumerable<NServiceBus.Features.FeatureActivator.FeatureState> featuresToActivate, NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.SetupFeatures(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Configure.Initialize() Unknown
NServiceBus.Core.dll!NServiceBus.Bus.Create(NServiceBus.BusConfiguration configuration) Unknown
RZ.Integration.Server.dll!RZ.Integration.Config.NServiceBus.UnicastBusConfigProvider.GetConfiguration() Line 25 C#
NServiceBus.Core.dll!NServiceBus.SettingsExtentions.GetConfigSection<NServiceBus.Config.UnicastBusConfig>(NServiceBus.Settings.ReadOnlySettings settings) Unknown
NServiceBus.Core.dll!NServiceBus.Features.UnicastBus.RegisterMessageOwnersAndBusAddress(NServiceBus.Features.FeatureConfigurationContext context, System.Collections.Generic.IEnumerable<System.Type> knownMessages) Unknown
NServiceBus.Core.dll!NServiceBus.Features.UnicastBus.Setup(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.ActivateFeature(NServiceBus.Features.FeatureActivator.FeatureState featureState, System.Collections.Generic.IEnumerable<NServiceBus.Features.FeatureActivator.FeatureState> featuresToActivate, NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Features.FeatureActivator.SetupFeatures(NServiceBus.Features.FeatureConfigurationContext context) Unknown
NServiceBus.Core.dll!NServiceBus.Configure.Initialize() Unknown
NServiceBus.Core.dll!NServiceBus.Bus.Create(NServiceBus.BusConfiguration configuration) Unknown
RZ.Integration.Server.dll!RZ.Integration.Config.NServiceBus.UnicastBusConfigProvider.GetConfiguration() Line 25 C#
NServiceBus.Core.dll!NServiceBus.SettingsExtentions.GetConfigSection<NServiceBus.Config.UnicastBusConfig>(NServiceBus.Settings.ReadOnlySettings settings) Unknown
NServiceBus.Core.dll!NServiceBus.Transports.Msmq.TimeToBeReceivedOverrideCheck.Run(NServiceBus.Configure config) Unknown
NServiceBus.Core.dll!NServiceBus.Configure.Initialize() Unknown
NServiceBus.Core.dll!NServiceBus.Bus.Create(NServiceBus.BusConfiguration configuration) Unknown
答案 0 :(得分:1)
每次调用者尝试访问它的配置时,都会创建实现IProvideConfiguration
的类(在您的情况下为UnicastBusConfig
)。您可以将第一个创建的实例保持为静态变量,并在调用GetConfiguration
实现的IProvideConfiguration
时始终返回相同的配置实例。我建议将任何初始化逻辑移出实现IProvideConfiguration
的类。