为什么没有数据仓库静态的? [英] Why aren't data repositories static?

查看:178
本文介绍了为什么没有数据仓库静态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆