Entity Framework Core service default lifetime

前端 未结 3 395
生来不讨喜
生来不讨喜 2020-11-27 12:53

In ASP.NET Core application I can register DbContext through DI like this

services.AddDbContext(options => options.UseNpgsql(         


        
3条回答
  •  温柔的废话
    2020-11-27 13:11

    Admittedly anecdotal, this is what I’ve learned. And it’s from a lazy KISS devotion. I avoided other complications and solved my issue of premature EF Core DbContext disposes w/o concern of pools, scopes etc. I was merely throwing together a POC w/o regard to async return values, chained up from the Controller to a Repository and so on, which all essentially returned “void”, i.e. literally the singular, “Task”. That caused iterations amongst my DbContext members in lower routines to inexplicably dispose of the underlying DbContext. All I had to do was make every async method return a Task value and everything worked. EF Core don’t like async void return values.

提交回复
热议问题