ambientcontext

Access IServiceProvider when using generic IHostBuilder

时间秒杀一切 提交于 2019-12-24 10:38:24
问题 I'm using IHostBuilder in a .NET Core 2.1 console application. Main looks like this: public static async Task Main(string[] args) { var hostBuilder = new HostBuilder() .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureServices(services => { // Register dependencies // ... // Add the hosted service containing the application flow services.AddHostedService<RoomService>(); }); await hostBuilder.RunConsoleAsync(); } } Before, with IWebHostBuilder , I had the Configure()