0

NServiceBus を 2.6 から 3.3 にアップグレードした後、CommandService がスローSystem.NullReferenceException: Object reference not set to an instance of an object.を開始しましたIStartableBus.Start()。小規模な調査によると、返される UnicastBusConfigure.CreateBus()の Transport プロパティ値は null であることが示されています。

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;
    }
}

誰かがこれに遭遇し、解決策を見つけましたか?

4

1 に答える 1

0

私は NCQRS を使用していませんが、実際の構成オブジェクトをリークしていると思います。

呼び出すとき.InstallNcqrs()(これは流暢な構成をコンパイルするための拡張メソッドであるべきではありませんか?)、渡された NServiceBus.Configure オブジェクトを返すのではなく、独自の NcqrsNsbConfigure オブジェクトを返します。確かに、入ってくる Configure オブジェクトと一致するように Builder と Configurer を提供しますが、NServiceBus パイプラインの残りの部分が現在期待している他の要素をリークしている可能性があります。

必要な NCQRS のものを初期化するようにコードを再配置しようとしますが、元の Configure オブジェクトを返します。返されたオブジェクトを使用して、他の流暢なメソッドを呼び出して NCQRS を構成していないので、問題になるとは思いません。

于 2012-12-04T22:54:45.977 に答える