为什么没有数据仓库静态的? [英] Why aren't data repositories static?
问题描述
我一直在寻找一个ASP.NET MVC应用程序库的方法,发现没有使用一个静态类。由于回购是CRUD,为什么不让它静态的?
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)你经常想有1库实例每个请求,使其更容易,以确保从一个用户的未提交的更改不会胡来为其他用户。
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.
这篇关于为什么没有数据仓库静态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!