I recently updated MassTransit from version 7.x to 8.x in our web applications (ASP.Net and ASP.Net Core with Azure Service Bus). Everything went quite smoothly except one point : MassTransit automatically adds an IHostedService for MassTransit.
It should be a nice option for the vast majority of users but I need to be able to decide if the bus must be started or not with the application. This need comes from our maintenance mode who prevent any communication on the bus when activated.
After investigating, I found the RemoveMassTransitHostedService extension method solution in another post. It seems to do the job but I didn't find a lot of information about the way to proceed. Do I need to manually connect some more wires by hand after calling this method? Is it a safe approach?
public void ConfigureServices(IServiceCollection services) {
services.AddMassTransit(x =>
{
// ...
x.UsingAzureServiceBus((context, cfg) =>
{
// ...
}
});
services.RemoveMassTransitHostedService();
}