Configure UniCastBus in NServiceBus using IWantToRunBeforeConfigurationIsFinalized

StackOverflow https://stackoverflow.com/questions/21735127

  •  10-10-2022
  •  | 
  •  

Domanda

I would like to "hook in" and tweak configuration to UnicastBus and was looking at doing this using IWantToRunBeforeConfigurationIsFinalized.

I would like to tweak/set the value for: ForwardReceivedMessagesTo. Any ideas on how that should be done?

È stato utile?

Soluzione

Unfortunately due to a bug (see https://github.com/Particular/NServiceBus/issues/1960), the only possible way is to programmatically replace the whole UnicastBusConfig, eg:

class Foo : IProvideConfiguration<UnicastBusConfig>
{
    public UnicastBusConfig GetConfiguration()
    {
        var unicastBusConfig = new UnicastBusConfig
        {
            ForwardReceivedMessagesTo = "FooBar",
        };
        unicastBusConfig.MessageEndpointMappings = new MessageEndpointMappingCollection();
        unicastBusConfig.MessageEndpointMappings.Add(...);

        return unicastBusConfig;
    }
}

But that is quite ugly :(

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top