注:接口代码、类库代码参考:.net core (.net 6) IOC容器注入--内置容器
Autofac容器优点:灵活(属性注入、多种生命周期、AOP扩展)、比较流行(技术门槛低)
1、引入NuGet包
Autofac Autofac.Extensions.DependencyInjection
2、替换容器使用autofac
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());//替换容器
3、使用autofac注册ITestServiceA
builder.Host.ConfigureContainer<ContainerBuilder>((context, containerBuilder) => { containerBuilder.RegisterType<TestServiceA>().As<ITestServiceA>(); });
标签:core,Autofac,容器,autofac,net,IOC From: https://www.cnblogs.com/yyd-sun/p/17014776.html