Faizan S.
Faizan S.

Reputation: 8644

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 better 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!

Upvotes: 12

Views: 1311

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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.

Upvotes: 13

Related Questions