I am using MassTransit with RabbitMQ in a ASP.Net Core (.Net 6) microservices project. Now I have upgraded to MassTransit Version 8. Currently I am using a IHostedService to start and stop the Bus:
public class BusService : IHostedService
{
private readonly IBusControl _busCtrl;
public BusService( IBusControl busCtrl )
{
_busCtrl = busCtrl ?? throw new ArgumentNullException( nameof( busCtrl ) );
}
public Task StartAsync( CancellationToken cancellationToken )
=> _busCtrl.StartAsync( cancellationToken );
public Task StopAsync( CancellationToken cancellationToken )
=> _busCtrl.StopAsync( cancellationToken );
}
Service Registration:
services.AddSingleton<IHostedService, BusService>();
I read now that "MassTransit will automatically add an IHostedService for MassTransit". So does this mean that I don't need such a Service to start/stop the bus anymore?