The use of Repository and unit of work patterns (revisited) … in EF Core with ASP.NET Core

前端 未结 1 1746
梦如初夏
梦如初夏 2021-02-07 12:02

I was following this tutorial for EF Core with ASP.NET Core. The interesting thing is that this article states that \'the use of Repository and unit of work patterns is not alwa

相关标签:
1条回答
  • 2021-02-07 12:23

    There's many reasons and a long history for why there's so much confusion here. EF's DbContext used to not implement an interface, so it made mocking it difficult for testing purposes. However, that was corrected in EF 6, so since that time there's been absolutely no benefit, even for testing purposes, in using the repository/unit of work patterns.

    EF Core is completely testable end-to-end and has an in-memory database provider as well now, which means you don't even need to mock it, though you very much can if you want.

    Long and short, dump the repository and unit of work patterns. They've never been a good solution even when they had some use for testing, and since EF 6, they have been completely useless.

    Now... let the flame war begin.

    0 讨论(0)
提交回复
热议问题