在将NServiceBus从2.6升级到3.3之后,CommandService开始在IStartableBus.Start()上抛出System.NullReferenceException: Object reference not set to an instance of an object.。小型研究表明,Configure.CreateBus()返回的UnicastBus的传输属性值为空。
Global.asax.cs中有NSB配置:
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;
}
}有没有人遇到过这个问题并找到了解决方案?
发布于 2012-12-05 06:54:46
我没有使用过NCQRS,但我猜你泄漏的是真正的配置对象。
当您调用.InstallNcqrs()时(这不应该是一个扩展方法以便使流畅的配置进行编译吗?)您返回的不是传入的NServiceBus.Configure对象,而是您自己的NcqrsNsbConfigure对象。当然,您提供了生成器和配置器来匹配传入的Configure对象,但您可能会泄漏NServiceBus管道的其余部分现在所期望的其他元素。
我将尝试重新排列您的代码,以便您初始化所需的NCQRS内容,但随后返回原始的配置对象。您没有使用返回的对象调用任何其他fluent方法来配置NCQRS,所以我认为这不应该是问题。
https://stackoverflow.com/questions/13701524
复制相似问题