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); }
原文地址:https://www.cnblogs.com/hack301/p/9632739.html
时间: 2024-10-10 03:25:39