Why aren't data repositories static?

人走茶凉 提交于 2019-12-05 14:21:45

问题


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 CRUD, why not make it static?


回答1:


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.




回答2:


Repository pattern increase testability, static classed decreases it.



来源:https://stackoverflow.com/questions/5622592/why-arent-data-repositories-static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!