Question

I'm using NServiceBus 4.0.3 with the Ninject builder and cannot figure out how to register message mutators (IMutateTransportMessages).

I've registered the mutator with the Ninject Kernel but it is never invoked. Below is how I'm configuring NServiceBus:

private static IBus ConfigureBus(IKernel kernel)
{
    kernel.Bind<IMutateTransportMessages>().To<SendTenantIdMutator>();

    return NServiceBus.Configure.With()
        .NinjectBuilder(kernel)
        .XmlSerializer()
        .MsmqTransport()
            .IsTransactional(false)
            .PurgeOnStartup(true)
        .UnicastBus()
            .LoadMessageHandlers()
        .CreateBus()
        .Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());
}
Was it helpful?

Solution

Is there some special reason to register the mutator directly with Ninject as opposed to the regular NServiceBus container API:

Configure.Component<SendTenantIdMutator>(Dependency‌​Lifecycle.SingleInstance);

I mean, this just calls internally into the configured container, which in your case would be Ninject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top