小编JSt*_*ein的帖子

在 ASP.NET Core 3.0 Preview 5 或更高版本中配置 AutoFac

按照 AutoFac 文档,我能够在 ASP.NET Core 3.0 Preview 3 中使用 AutoFac。ASP.NET Core 3.0 Preview 4 和 ASP.NET Core 3.0 Preview 5 引入了重大更改,AutoFac 不再有效。我的控制器方法返回运行时错误。

我的代码中ASP.NET Core 3.0 Preview 3和ASP.NET Core 3.0 Preview 5的区别如下:

IWebHostBuilder -> IHostBuilder

CreateWebHostBuilder -> CreateHostBuilder

WebHost.CreateDefaultBuilder(args) -> Host.CreateDefaultBuilder(args)

public IServiceProvider ConfigureServices(IServiceCollection services)
Run Code Online (Sandbox Code Playgroud)

public void ConfigureServices(IServiceCollection services)
Run Code Online (Sandbox Code Playgroud)
System.AggregateException
  HResult=0x80131500
  Message=Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: API.Controllers.CityController Lifetime: Transient ImplementationType: CityController': Unable to resolve service for type 'IUnitOfWork' while attempting …
Run Code Online (Sandbox Code Playgroud)

c# asp.net dependency-injection autofac autofac-configuration

6
推荐指数
1
解决办法
8564
查看次数