How to remove the NHibernateMessageModule from being called in NServiceBus?
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.
精彩评论