0

I would like the configure MassTransit Message at runtime. I could not find a way to do this and was wondering if I missed something or if it is not possible. Here is what it currently looks like:

var azureServiceBus = Bus.Factory.CreateUsingAzureServiceBus(busConfig =>
{
    busConfig.Message<MyType>(configTopology =>
    {
        // Do some configuration
    });
});

This is what I would like to do though:

var azureServiceBus = Bus.Factory.CreateUsingAzureServiceBus(busConfig =>
{
    foreach (var myType in myTypes)
    {
        busConfig.Message(myType, configTopology =>
        {
            // Do some configuration
        });
    }
});
Jon49
  • 4,444
  • 4
  • 36
  • 73

1 Answers1

2

There are no overloads from Message that accept a Type argument, the types must be specified as a generic type argument. You could, however, use an approach to call a generic method at runtime specifying a type argument as seen in this question.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • 1
    I ended up creating a private method in the wrapper class which calls all the methods from the bus so there is only one part which is dynamically calling a generic method. It worked out really well! – Jon49 Mar 31 '20 at 23:24