Why is throwing the exception: AddMassTransit() was already called and may only be called once per container?

296 Views Asked by At

I'm adding the configuration of Mass transit for azure service bus in my ConfigureServices. I'm using .Net6 and Mass Transit 8.0.15. I'm debugging my project ti check if I'm getting the right connection string for the azure service bus but I get an exception. This is the code I have:

public class DigitalConsultantsDataServicesModule : IServicesModule
{
    public void ConfigureServices(IServiceCollection services, IHostEnvironment environment, ConfigurationManager configuration)
    {
        services.AddDbContext<DigitalConsultantsDbContext>(options =>
        {
            options.UseSqlServer(configuration.GetConnectionString("HahnSuiteDigitalConsultants"));
            options.EnableDetailedErrors(configuration.GetValue("EfCore:HahnSuiteDigitalConsultants:DetailedErrors",
                environment.IsDevelopment()));
            options.EnableSensitiveDataLogging(configuration.GetValue("EfCore:HahnSuiteDigitalConsultants:SensitiveDataLogging",
                false));
        });

        services.AddScoped(typeof(IEntityRepository<>), typeof(DigitalConsultantsEntityRepository<>));

        //This is the configuration I added here
        services.AddMassTransit(x => x.UsingAzureServiceBus((context, configuration) =>
        {
            var connectionString = context.GetService<IConfiguration>().GetValue<string>("ServiceBus");
            configuration.Host(connectionString);
        }
        ));
    }
}

About this I'm getting the following exception:

MassTransit.ConfigurationException: 'AddMassTransit() was already called and may only be called once per container. To configure additional bus instances, refer to the documentation: https://masstransit-project.com/usage/containers/multibus.html'

This is my first time using Mass Transit and I just install it. I didn't put any other configuration so I'm not sure where should be the othe call to AddMassTransit.

0

There are 0 best solutions below