Dependency injection in ASP.NET Core 2 throws exception

前端 未结 5 722
失恋的感觉
失恋的感觉 2020-12-13 09:15

I receive following exception when I try to use custom DbContext in Configure method in Startup.cs file. I use ASP.NET Core in version 2.0.0-previe

5条回答
  •  遥遥无期
    2020-12-13 09:45

    In ASP.NET Core 2.0 and newer you can simply inject the scoped service you need into the Configure constructor, like you tried to do initially:

    public void Configure(
        IApplicationBuilder app,
        IHostingEnvironment env,
        ILoggerFactory loggerFactory,
        CommunicatorContext dbContext,
        ILdapService ldapService)
    {
      // ...
    }
    

    This is a lot easier, thanks to the improvements in #1106.

提交回复
热议问题