开发者

Why aren't data repositories static?

I wa开发者_如何学Cs 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) 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.


Repository pattern increase testability, static classed decreases it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜