將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;
}
}
有沒有人碰到這一點,並找到了解決辦法?
'configure.CreateBus().Start()'即使它是NServiceBus.Configure對象也失敗,我只是簡單地調用'NcqrsNsbConfigure.Install(configure)'而不使用結果 – VladK
如果你忽略調用'NcqrsNsbConfigure.Install(configure)'? –
是的。如果NcqrsNsbConfigure.Install(configure)調用忽略,它會發生。 – VladK