views:

76

answers:

2

I am not using the nhibernate saga persistence and hence I do not need the NHibernateMessageModule.

So how do i remove it?

A: 

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.

Simon
Actually it doesn't work :(The NHibernateMessageModule still gets called.
John Simons
A: 

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.

Udi Dahan