开发者

How to remove the NHibernateMessageModule from being called in NServiceBus?

开发者 https://www.devze.com 2023-01-02 15:09 出处:网络
I am not using the nhibernate saga persistence and he开发者_开发技巧nce I do not need the NHibernateMessageModule.

I am not using the nhibernate saga persistence and he开发者_开发技巧nce I do not need the NHibernateMessageModule.

So how do i remove it?


You have to remove the module from the container before starting the bus, because afterwards it gets cached. You can do this by calling .RunCustomAction() before .CreateBus().Start() and including your code in there.

Internally, the CastleWindsorBuilder does this:

Component.For(GetAllServiceTypesFor(concreteComponent)).ImplementedBy(concreteComponent);

So you might also need to remove the component for all the interfaces it is registered - meaning IMessageModule.


So far I have this.

Note I am using Castle Windsor as the container.

After NServiceBus has done its configuration

var container = new WindsorContainer();
NServiceBus.Configure.With()
    .CastleWindsorBuilder(container)
    .XmlSerializer()
    .MsmqTransport()
        .IsTransactional(false)
        .PurgeOnStartup(false)
    .UnicastBus()
        .ImpersonateSender(false)
        .LoadMessageHandlers();

I remove the component from Castle Windsor

container.Kernel.RemoveComponent("NServiceBus.SagaPersisters.NHibernate.NHibernateMessageModule");

Not the most elegant approach but it works.

I am hoping there is a better way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号