ASP.Net Core 3.1 With Autofac ConfigureServices returning an System.IServiceProvider isn't suppor...
ASP.Net Core 3.1 With Autofac ConfigureServices returning an System.IServiceProvider isn't supported. 前言 Autofac在ASP.Net Core3.0以后,集成方式有所调整。在ASP.Net Core2中我们一般是把 Startup 的 ConfigureServices 方法返回值类型改为 IServiceProvider 。我们可以先看一下部分代码: public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); //xxxxxx你的其他代码 省略........... //用Autofac来替换IOC容器 返回值由 void 修改为 IServiceProvider var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule<CustomAutofacModule>(); containerBuilder.Populate(services); var container = containerBuilder.Build(); //将当前的容器保存起来