1.nuget Autofac Autofac.Extensions.DependencyInjection
2.将Startup.cs中的
ConfigureServices
返回类型改为IServiceProvider
public IServiceProvider ConfigureServices(IServiceCollection services){ ???services.AddMvc(); ?? 可以将下面代码单独放入到一个文件
??var builder = new ContainerBuilder(); ???builder.Populate(services); ???builder.RegisterAssemblyTypes(typeof(Startup).Assembly).AsImplementedInterfaces(); ???var Container = builder.Build(); ???return new AutofacServiceProvider(Container);}
.net core 使用Autofac
原文地址:https://www.cnblogs.com/hack301/p/9632739.html