将 NServiceBus 从 2.6 升级到 3.3 后,CommandService 开始System.NullReferenceException: Object reference not set to an instance of an object.
运行IStartableBus.Start()
。小型研究表明,返回的 UnicastBusConfigure.CreateBus()
具有 null 作为 Transport 属性值。
Global.asax.cs 中有 NSB Config:
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;
}
}
有没有人遇到过这个并找到了解决方案?