Using Autofac with ASP.Net Core 3.1 generic host “Worker Service” application
问题 In an ASP.Net Core application, its easy to configure Autofac using: public class Program { public static void Main(string[] args) { // ASP.NET Core 3.0+: // The UseServiceProviderFactory call attaches the // Autofac provider to the generic hosting mechanism. var host = Host.CreateDefaultBuilder(args) .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webHostBuilder => { webHostBuilder .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration()