Pros and cons of having static repositories in ASP.NET MVC application
What are the pros and cons of using static repositories in an ASP.NET MVC application?
Wouldn't it be bette开发者_开发技巧r to have all the methods available all the time -> means that the class get's instantiated only once instead of having multiple controllers referencing to the same repository class and its methods?
Or do I get something wrong here?
All help is more than appreciated!
Pros:
- Repository is accessible everywhere
Cons:
- Repositories don't implement a contract which leads to a strong coupling between consumers of the repository and the implementation
- Impossible to unit test
- Might run into threading issues
Remark: Instantiating the repository on every request shouldn't be regarded as a performance issue.
精彩评论