Wednesday, April 1, 2020

ConfigureServices returning an System.IServiceProvider isn't supported.

Alright, if you are getting this error, you tried to loop in Autofac as described here and it did not work because you are using version 3 of the .NET Framework (or better). The fix is to undo what you did in ConfigureServices and instead, in Program.cs, add the third line you see below to the mix:

public static IHostBuilder CreateHostBuilder(string[] args) =>
      Host.CreateDefaultBuilder(args)
         .UseServiceProviderFactory(new AutofacServiceProviderFactory())
         .ConfigureWebHostDefaults(webBuilder =>
         {
            webBuilder.UseStartup();
         });

 
 

Alright, now back at Startup.cs you need a new method called ConfigureContainer like so:

public void ConfigureContainer(ContainerBuilder builder)
{
   builder.RegisterType<Tom>().As<ITom>();
}

No comments:

Post a Comment