.Net Core 2.1 + MassTransit - 无法访问已处置的 object.Object 名称:'IServiceProvider'

.Net Core 2.1 + MassTransit - Cannot access a disposed object.Object name: 'IServiceProvider'

我正在使用 .NET Core 2.1 和 MassTransit 开发应用程序。 我收到以下错误:

Object name: 'IServiceProvider'., System.ObjectDisposedException: Cannot access a disposed object.

在配置服务中

public void ConfigureServices(IServiceCollection services)
{
        services.InitializeTelegramBot(Configuration);
        //RabbitMQ register consumer
        services.Configure<RabbitMqConfiguration>(Configuration.GetSection("RabbitMqConfiguration"));
        services.AddMassTransit(configurator =>
        {
            configurator.AddConsumer<Sender>();
        });
        services.AddScoped<Sender>();
        //services.AddSingleton<IApplicationLifetime, ApplicationLifetime>();
}

在配置中

public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, IHostingEnvironment env, IApplicationLifetime applicationLifetime)
{
        //RabbitMq register msg bus
        var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
        {
            var rabbitOptions = new RabbitMqConfiguration();
            this.Configuration.GetSection("RabbitMqConfiguration").Bind(rabbitOptions);
            IRabbitMqHost host = cfg.Host(new Uri(rabbitOptions.HostAdress), _ =>
            {
                _.Username(rabbitOptions.Username);
                _.Password(rabbitOptions.Password);
            });
            cfg.ReceiveEndpoint(host, rabbitOptions.TerminalCfgEndpoint, conf =>
            {
                conf.LoadFrom(serviceProvider);
            });
            cfg.PrefetchCount = 1;//Consume messages 1 by 1
        });
        applicationLifetime.ApplicationStarted.Register(bus.Start);
        applicationLifetime.ApplicationStopped.Register(bus.Stop);
}

完整 StackTrace

 Object name: 'IServiceProvider'., System.ObjectDisposedException: Cannot 
    access a disposed object.
    Object name: 'IServiceProvider'.
    at 
 Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at MassTransit.ExtensionsDependencyInjectionIntegration.DependencyInjectionConsumerScopeProvider.MassTransit.Scoping.IConsumerScopeProvider.GetScope[TConsumer,T](ConsumeContext`1 context)
   at MassTransit.Scoping.ScopeConsumerFactory`1.Send[TMessage](ConsumeContext`1 context, IPipe`1 next)
   at MassTransit.Pipeline.Filters.ConsumerMessageFilter`2.GreenPipes.IFilter<MassTransit.ConsumeContext<TMessage>>.Send(ConsumeContext`1 context, IPipe`1 next)

如有任何帮助,我将不胜感激。我希望我问的很清楚。

MassTransit container configuration 有据可查。

还有一个configuration section for .NET Core.

此外,现代版本的 MassTransit 不再支持 LoadFrom