2012-12-04 39 views
0

將NServiceBus從2.6升級到3.3之後CommandService開始在IStartableBus.Start()上拋出System.NullReferenceException: Object reference not set to an instance of an object.。小型研究表明,由Configure.CreateBus()返回的UnicastBus具有空的Transport屬性值。ncqrs與NServiceBus 3.3

有NSB配置中的Global.asax.cs:

IBus bus = Configure.With() 
    .DefineEndpointName(endpointName) 
    .UnityBuilder(unityContainer) 
    .AddLogger() 
    .BinarySerializer() 
    .MsmqTransport() 
    .PurgeOnStartup(false) 
    .IsTransactional(true) 
    .IsolationLevel(TransactionIsolationLevel) 
    .TransactionTimeout(TimeSpan.FromMinutes(TransactionTimeout)) 
    .UnicastBus() 
    .ImpersonateSender(true) 
    .LoadMessageHandlers() 
    .MsmqSubscriptionStorage() 
    .InstallNcqrs() 
    .CreateBus() 
    .Start(); 


public class NcqrsNsbConfigure : NServiceBus.Configure 
{ 
    private NsbCommandService _commandService; 
    private InProcessEventBus _inProcessEventBus; 

    public static NcqrsNsbConfigure InstallNcqrs(NServiceBus.Configure config) 
    { 
     var configNcqrs = new NcqrsNsbConfigure(); 
     configNcqrs.Install(config); 
     return configNcqrs; 
    } 

    public void Install(NServiceBus.Configure config) 
    { 
     Builder = config.Builder; 
     Configurer = config.Configurer; 

     NcqrsEnvironment.Configure(new NsbEnvironmentConfiguration(Builder)); 
     var compositeBus = new CompositeEventBus(); 
     _inProcessEventBus = new SafeInProcessEventBus(); 
     compositeBus.AddBus(_inProcessEventBus); 
     compositeBus.AddBus(new NsbEventBusWrapper()); 
     NcqrsEnvironment.SetDefault<IEventBus>(compositeBus); 
     _commandService = new NsbCommandService(); 
     var safeCommandService = new NSBCommandService(NcqrsEnvironment.Get<IBus>(), _commandService); 
     config.Configurer.RegisterSingleton(typeof(Ncqrs.Commanding.ServiceModel.ICommandService), safeCommandService); 
    } 

    public NcqrsNsbConfigure RegisterExecutor<TCommand>(ICommandExecutor<TCommand> executor) where TCommand : Ncqrs.Commanding.ICommand 
    { 
     _commandService.RegisterExecutor(executor); 
     return this; 
    } 

    public NcqrsNsbConfigure RegisterInProcessEventHandler<TEvent>(IEventHandler<TEvent> handler) where TEvent : Ncqrs.Eventing.IEvent 
    { 
     _inProcessEventBus.RegisterHandler(handler); 
     return this; 
    } 

    public NcqrsNsbConfigure RegisterInProcessEventHandler(Type eventType, Action<Ncqrs.Eventing.IEvent> handler) 
    { 
     _inProcessEventBus.RegisterHandler(eventType, handler); 
     return this; 
    } 

    public NcqrsNsbConfigure RegisterAllInProcessEventHandlers(Assembly asm) 
    { 
     _inProcessEventBus.RegisterAllHandlersInAssembly(asm); 
     return this; 
    } 
} 

有沒有人碰到這一點,並找到了解決辦法?

回答

0

我還沒有使用NCQRS,但我猜測你正在泄漏真正的配置對象。

當您調用.InstallNcqrs()(並且不應該爲擴展方法來使流暢配置編譯?),則不會返回NServiceBus.Configure對象中的傳遞對象,而是返回自己的NcqrsNsbConfigure對象。當然,你提供Builder和Configurer來匹配傳入的Configure對象,但也許你正在泄漏NServiceBus管道現在所期望的其他元素。

我會嘗試重新排列代碼,以便初始化您需要的NCQRS事物,但返回原始配置對象。您沒有使用返回的對象來調用任何其他流利的方法來配置NCQRS,所以我不認爲這應該是一個問題。

+0

'configure.CreateBus().Start()'即使它是NServiceBus.Configure對象也失敗,我只是簡單地調用'NcqrsNsbConfigure.Install(configure)'而不使用結果 – VladK

+0

如果你忽略調用'NcqrsNsbConfigure.Install(configure)'? –

+0

是的。如果NcqrsNsbConfigure.Install(configure)調用忽略,它會發生。 – VladK