Why aren't data repositories static?

前端 未结 2 1493
说谎
说谎 2021-02-19 10:53

I was looking at the repository method for an ASP.NET MVC app and noticed a static class wasn\'t used.

Since the repo is CR

相关标签:
2条回答
  • 2021-02-19 11:32

    1) It's difficult to do unit testing with static classes (if you are testing a class that depends on your repository, you want that test to work against a fake 'mocked' repository object instead of your real one)

    2) You often want to have 1 repository instance per-request to make it easier to ensure that uncommited changes from one user don't mess things up for another user.

    0 讨论(0)
  • 2021-02-19 11:33

    Repository pattern increase testability, static classed decreases it.

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