你的位置: 码友网首页 / 资讯源列表 / Avoid Wrapping DbContext in Using (and other gotchas)

关于[Avoid Wrapping DbContext in Using (and other gotchas)]的摘要:

EF and EF Core DbContext types implement IDisposable. As such, best practice programming suggests that you should wrap them in a using() block (or new C# 8 using statement). Unfortunately, doing this, at least in web apps, is generally a bad idea. I work with a lot of clients who are migrating from .NET Framework to .NET Core and .NET 5. Some of them weren't using dependency injection in their legacy apps, or weren't using it consistently. As a result, many of them have a TON of instantiations of their DbContext classes. Doing this has its own issues, not the least of which is the tight coupling it introduces (see New is Glue).

原文地址: https://ardalis.com/avoid-wrapping-dbcontext-in-using/

收录时间: 2020-12-03 浏览量: 2460 分类: C#开发

| 0 收藏 | 0